What is the difference between the selectors “.class.class” and “.class .class”?

后端 未结 4 612
故里飘歌
故里飘歌 2020-12-12 14:21

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

相关标签:
4条回答
  • 2020-12-12 14:42

    .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.

    0 讨论(0)
  • 2020-12-12 14:44

    .class.class can also be used avoid the use of !important in case that a higher specificity selector prevents your rule from being applied.

    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 {}
    
    0 讨论(0)
  • 2020-12-12 14:50
    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>
      
    0 讨论(0)
  • 2020-12-12 15:08
    .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

    0 讨论(0)
提交回复
热议问题