CSS: child selector (>)
Match a Parent Tag (aka Child Combinator)
s1 > s2-
Match any s2 that is a direct child of s1.
Each expression can be compound selector.
Can also be chained like this:
a > b > c/* any span that's direct child of div */ div > span { color: red; } <div> <span>match</span> </div> <div> <p> <span>no</span> </p> </div>
Example. Less space of h2 inside section
/* the first h2 after section */ section > h2 { margin-top: 1ex; }
CSS, Selectors
simple selectors
- CSS: element selector (tag name)
- CSS: universal selector (* any tag)
- CSS: class selector
- CSS: ID selector
- CSS: attribute selector
- CSS: multiple attributes selector
selector list
relationship selectors (combinators)
- CSS: descendant selector (space)
- CSS: child selector (>)
- CSS: subsequent sibling selector (~)
- CSS: adjacent sibling selector (+)
special selector
- CSS: :root selector
- CSS: no child selector
- CSS: sibling rank selector (first, last, nth)
- CSS: nth-child selector
- CSS: pseudo-class selector (:)
- CSS: pseudo-element selector (::)
- CSS: negation selector (:not)
- CSS: is any of selector (:is, :where)
- CSS: :has descendant selector