2

Possible Duplicate:
What does “>” mean in CSS rules?

CSS has the following two syntaxes which seem to be doing the same thing. Selecting a nested element.

div span

div > span

Am I missing something, or are these two indeed equivalent selectors ?

Community
  • 1
  • 1
Parag
  • 12,093
  • 16
  • 57
  • 75
  • Could you mark it as duplicate instead of closing it? I asked the question here, because SO normally focuses on more programming related questions. Thanks the link helped. Edit: I guess you are right, this does belong to SO. – Parag May 21 '12 at 09:09
  • Unfortunately I can't mark things as duplicate if the duplicate is on a different StackExchange site from Webmasters. (It's a limitation/design choice of the SE software.) Sorry! – Nick May 21 '12 at 09:54
  • @Nick: Now that the question has been migrated, I've closed it here. Thanks for flagging! – BoltClock May 21 '12 at 18:04

2 Answers2

10

No, they are not equivalent. The first one is the descendant selector, while the second is the child selector.

Quick example:

<div class="a">
  <div class="b">
    <div class="c"></div>
  </div>
</div>

With this markup .a > .c will select nothing, while .a .c and .a > .b > .c will select the innermost element.

Jon
  • 428,835
  • 81
  • 738
  • 806
3
div span

Will select any span that is inside any div. This could be multiple levels deep.

div > span

Will only select any spans that are the direct descendants of a div. More info about child selectors -> http://meyerweb.com/eric/articles/webrev/200006b.html

Undefined
  • 11,234
  • 5
  • 37
  • 62