A CSS combinator expresses a relationship between selectors, letting you style elements by their position in HTML instead of adding more class or ID names. CSS provides four: descendant (space), child (>), adjacent sibling (+), and general sibling (~). section 1.6.2
Use the relationship that matches the structure you want to target:
- A descendant combinator selects matching elements anywhere inside a parent, including children, grandchildren, and deeper descendants: article p. section 1.6.2
- A child combinator selects only immediate children: .list > li styles first-level list items without changing nested items. section 1.6.2
Style only the first-level list items
Given a nested unordered list, .list > li { color: crimson; } changes the direct list items while leaving nested items unaffected. A descendant selector such as .list > li ul can separately address the nested lists.
Browse the relationship diagram to compare parent, child, descendant, and sibling structures before writing a selector. section 1.6.2
