“div .class”、“.class”之间的区别和'.class div'
我有一个像这样的 div:
我注意到 div.class 可以处理这种样式,而 .class div 则不能。此外,.class 还可以处理样式。
这是为什么 ?
I have a div like : <div class='class'>
I notice that div.class handles this style, while .class div does not. Moreover, .class handles the style as well.
Why is that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
div.class
查找存在class
类的div
。.class div
查找作为具有class
类的元素的后代的div
。您的元素是一个带有
class
类的 div ,因此选择器不会选择它。.class
将选择具有该类的任何元素,包括任何div
元素。div.class
looks for adiv
with theclass
class present..class div
looks for adiv
that is a descendent of an element with theclass
class.Your element is a
div
with theclass
class, hence the selector does not select it..class
will select any element with that class, including anydiv
elements.空格是一个后代选择器,即“仅当其祖先之一与左侧匹配时才匹配右侧”。
请参阅Selectutorial
.class
的后代部分可以正常工作,因为任何与规则“A div is a member of the class 'class'”匹配的元素都会也符合规则“A member of the class 'class'”,只是不太具体。
A space is a descendent selector, i.e. "Matches the right hand side only if one of its ancestors matches the left hand side".
See the descendant section of Selectutorial
.class
works because any element that matches the rule "A div that is a member of the class 'class'" will also match the rule "A member of the class 'class'", it is just less specific.div.class
指的是类为“class”的所有 div。另一方面,.class div
指的是属于“class”类元素的子元素的所有 div。.class
指的是类为“class”的所有元素。div.class
refers to all divs with the class 'class.'.class div
, on the other hand, refers to all divs that are children of the element with the class 'class.'.class
refers to all elements with the class 'class.'值“类”。可以写成 div[class="class"]
一个 div 是任何的后代
具有 value 类属性的元素
“班级”。可以写为 [class="class"] div
值“class”的类属性。可以写成 [class="class"]
虽然点、句号、句号、. , 被用来代替。
of value "class". Can be written as div[class="class"]
a div which is a decendant of any
element which has a class attribute of value
"class". Can be written as [class="class"] div
class attribute of value "class". Can be written as [class="class"]
Although the dot, fullstop, period, . , is used instead.