1

These two Selectors:

.class>li>a{}

and

.class li a{}

are doing exactly same job for me so can some one please tell me what is the benefit of using > ?

Thanks

user2864740
  • 60,010
  • 15
  • 145
  • 220
Suffii
  • 5,694
  • 15
  • 55
  • 92

2 Answers2

7

It makes the selector more specific.

The first selector only targets an anchor tag that is a child tag of a lst item that is a child tag of a CLASS.

<div class="fo">
<li>
<a>

the second select will target all anchor tags that are a descendant of a list item which is a descendant of a specific class.

<div class="fo">
.....
<li>
.....
<a>

where .... can be any other dom element

gh9
  • 10,169
  • 10
  • 63
  • 96
  • 1
    Note that in CSS Selectors the terms of [`specific` / `specificity`](http://www.w3.org/TR/CSS2/cascade.html#specificity) have a special meaning. Technically, a child combinator `>` itself won't change the specificity value of a selector. – Hashem Qolami Oct 24 '14 at 21:13
  • 1
    Besides, `
  • ` stands for *list* item, not line item.
  • – Hashem Qolami Oct 24 '14 at 21:19
  • @HashemQolami good comments, I have edited the response to reflect LI better – gh9 Oct 27 '14 at 12:18