Please tell me the difference between following two methods of css
method 1:
.class1 .class2
method 2:
.class1 > .class2
Please tell me the difference between following two methods of css
method 1:
.class1 .class2
method 2:
.class1 > .class2
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
.
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>