CSS 选择器“.class.class”和“.class .class”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17391364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between the selectors ".class.class" and ".class .class"?
提问by Muhammad Umer
What is the different between .class.class
and .class .class
?
.class.class
和之间有什么区别.class .class
?
回答by esqew
.class .class
matches any elements of class .class
that are descendantsof another element with the class .class
.
.class .class
匹配类中的任何元素.class
是后代与类另一个元件的.class
。
.class.class
matches any element with both classes.
.class.class
匹配具有这两个类的任何元素。
回答by Pbk1303
.name1.name2
means a
div
or anelement
having both classes together, for example:<div class="name1 name2">...</div>
.name1.name2
表示将两个类放在一起的一个
div
或一个element
,例如:<div class="name1 name2">...</div>
.name1 .name2
means a
div
or anelement
which has a classname1
and any of its child nodes having classname2
<div class="name1"> <div class="name2"> ... </div> </div>
.name1 .name2
表示具有类及其任何具有类的子节点的a
div
或 anelement
name1
name2
<div class="name1"> <div class="name2"> ... </div> </div>
回答by MarcinJuraszek
.class1.class2
Element that has both class1
and class2
set within it's class
attribute (like that: class="class1 class2"
)
元素同时具有class1
和class2
设置它的内部class
属性(这样的:class="class1 class2"
)
.class1 .class2
Element with class2
that is a descendant of an element with class1
class
具有class2
该元素的元素是具有class1
类的元素的后代
回答by blanchart
.class.class
can also be used avoid the use of !important
in case that a higher specificity selector prevents your rule from being applied.
.class.class
也可以用于避免使用,!important
以防更高的特异性选择器阻止您的规则被应用。
In this case there are not two classes in an element. You just repeat the class which specificity you want to increase, like
在这种情况下,元素中没有两个类。你只需重复你想要增加的特异性的类,比如
(HTML) <div class="something">...</div>
(CSS) .something.something {}