-2

I'm currently reading Charles Wyke-Smith's book "Stylin' With CSS".

He has one section where there is nav.menu > ul {} AS WELL AS nav.menu ul {}.

What's the purpose of the > selector?

Danora
  • 315
  • 3
  • 9

2 Answers2

3

http://www.w3.org/TR/CSS2/selector.html

Quick Explanation:

E > F Matches any F element that is a child of an element E.

More detail from the same source:

A child selector matches when an element is the child of some element. A child selector is made up of two or more selectors separated by ">".

The following rule sets the style of all P elements that are children of BODY:

body > P { line-height: 1.3 } The following example combines descendant selectors and child selectors:

div ol>li p It matches a P element that is a descendant of an LI; the LI element must be the child of an OL element; the OL element must be a descendant of a DIV. Notice that the optional white space around the ">" combinator has been left out.

For information on selecting the first child of an element, please see the section on the :first-child pseudo-class below.

Dave
  • 28,833
  • 23
  • 113
  • 183
  • Where as the alternative matches any child in the chain rather than any descendant (e.g., child of a child would qualify without the `>`, but not with the `>`). – pickypg Apr 19 '13 at 05:20
2

It selects immediate children, as opposed to descendants at any point in the hierarchy.

David Hedlund
  • 128,221
  • 31
  • 203
  • 222