What is the difference between the selectors “.cla

2019-01-21 05:17发布

问题:

What is the different between .class.class and .class .class?

回答1:

.class .class matches any elements of class .class that are descendants of another element with the class .class.

.class.class matches any element with both classes.



回答2:

  1. .name1.name2

    means a div or an element having both classes together, for example:

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

  1. .name1 .name2

    means a div or an element which has a class name1 and any of its child nodes having class name2

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


回答3:

.class1.class2

Element that has both class1 and class2 set within it's class attribute (like that: class="class1 class2")

.class1 .class2

Element with class2 that is a descendant of an element with class1 class