8

I just want to know the difference between:

.class .class{
font-size:14px;
}

VS:

.class > .class{
font-size:14px;
}

Is the same thing?

1 Answer 1

16

No, they aren't the same - the first example is a descendant selector, the second is a direct child selector.


.class .class will target all elements with the class .class which derive from any element which has the class .class, e.g

<div class="class">
 <div class="other">
    <div class="class"> This is targeted. </div>
 </div> 
</div>

jsFiddle example


.class > .class will only target direct children of elements with the class .class, e.g

<div class="class">
   <div class="other">
      <div class="class">This isn't targeted.</div>
   </div> 
   <div class="class">
      <div class="class">This is targeted, as it is a direct child.</div>
   </div>    
</div>

jsFiddle example.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.