-2

Please tell me the difference between following two methods of css

method 1:

.class1 .class2

method 2:

.class1 > .class2
vinay Maneti
  • 1,447
  • 1
  • 23
  • 31
Dipen
  • 240
  • 1
  • 5
  • 17

2 Answers2

3

The first one will apply styles to any element with the class class2 when under, hierarchically, an element of class1.

The second will do the same but only when the element with class2 is directly under, as in the very next hierarchical level (a child and no further descendents), an element of class1.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
1

First select all .class2 which are descendants of .class1 Second select all .class2 which are direct children of class1

<div class="class1">
  <div class="class2>
    This will be selected by both 
  </div>
  <div>
    <div class="class2">
    This one only by first
    </div>
  </div>
</div>
Volvox
  • 1,639
  • 1
  • 12
  • 10