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.classand .class .class?
.class.class和之间有什么区别.class .class?
回答by esqew
.class .classmatches any elements of class .classthat are descendantsof another element with the class .class.
.class .class匹配类中的任何元素.class是后代与类另一个元件的.class。
.class.classmatches any element with both classes.
.class.class匹配具有这两个类的任何元素。
回答by Pbk1303
.name1.name2means a
divor anelementhaving both classes together, for example:<div class="name1 name2">...</div>
.name1.name2表示将两个类放在一起的一个
div或一个element,例如:<div class="name1 name2">...</div>
.name1 .name2means a
divor anelementwhich has a classname1and any of its child nodes having classname2<div class="name1"> <div class="name2"> ... </div> </div>
.name1 .name2表示具有类及其任何具有类的子节点的a
div或 anelementname1name2<div class="name1"> <div class="name2"> ... </div> </div>
回答by MarcinJuraszek
.class1.class2
Element that has both class1and class2set within it's classattribute (like that: class="class1 class2")
元素同时具有class1和class2设置它的内部class属性(这样的:class="class1 class2")
.class1 .class2
Element with class2that is a descendant of an element with class1class
具有class2该元素的元素是具有class1类的元素的后代
回答by blanchart
.class.classcan also be used avoid the use of !importantin 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 {}

