CSS: subsequent sibling selector (~)
Subsequent-Sibling Combinator
s1 ~ s2-
Match all s2 that has a older brother s1.
Each expression can be compound selector.
/* make list items red, except first */ li ~ li { color: red; } <ul> <li>cat</li> <li>dog (match)</li> <li>bird (match)</li> </ul>
Example. All paragraphs after a heading
/* all p elements that are siblings of h2 and come after it */ h2 ~ p { font-weight: bold; }
CSS selectors by sibling criteria
CSS. Selectors
Selector types
- CSS: types of selectors
- CSS: simple selectors
- CSS: compound selectors
- CSS: complex selector (combinator)
Simple selectors
- CSS: type selector (tag name)
- CSS: universal selector (* any tag)
- CSS: class selector (.x)
- CSS: ID selector (#)
- CSS: attribute selector ([x])
Combinators
- CSS: descendant selector (space)
- CSS: child selector (>)
- CSS: adjacent sibling selector (+)
- CSS: subsequent sibling selector (~)
Selector list
Special selector
- CSS: :root selector
- CSS: no child selector
- CSS: first child, sibling rank selector
- 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