What is the difference between “.class element” and “element.class”?

前端 未结 4 1194
独厮守ぢ
独厮守ぢ 2020-12-23 00:04

Is there a difference between .class element and element.class in a CSS selector?

I had always been shown element.class but j

4条回答
  •  清歌不尽
    2020-12-23 00:22

    "element.class" selects elements that have the given class.

    ".class element" selects all elements that are children of anything with the given class.

    Example:

    ...

    div.foo would select the div, while .foo p would select the child paragraph. It should be noted that without specifying direct child via the ">" selector, this will traverse the entire document tree when looking for children.

提交回复
热议问题