Tell class1 .class2 what the difference is: " class1 .class2 " (context classes) and " .class1.class2 " (???) And what and when is it better to use?

  • one
    the first entry indicates the content of one element in another, the second indicates the presence of both classes in one element. - etki
  • @Etki, that is, the second entry will work only if the element has strictly these two classes? For example, <div class="class1 class2> will work for the second record (and also for the first one), and <div class=class2> will work only for the first record ? - 111xbot111

1 answer 1

The .class1 .class2 entry will be applied to a block with class2, which lies inside class1:

 <div class="class1"> <div class="class2"></div> </div> 

The second entry will be applied to the block, which immediately has two classes - class1 and class2:

 <div class="class1 class2"></div>