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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:21:57  来源:igfitidea点击:

What is the difference between the selectors ".class.class" and ".class .class"?

csscss-selectors

提问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

  1. .name1.name2

    means a divor an elementhaving both classes together, for example:

    <div class="name1 name2">...</div>
    
  1. .name1.name2

    表示将两个类放在一起的一个div或一个element,例如:

    <div class="name1 name2">...</div>
    


  1. .name1 .name2

    means a divor an elementwhich has a class name1and any of its child nodes having class name2

    <div class="name1">
        <div class="name2">
            ...
        </div>
    </div>
    
  1. .name1 .name2

    表示具有类及其任何具有类的子节点的adiv或 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")

元素同时具有class1class2设置它的内部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 {}