Descendant selector in CSS - Deep Dive
┌─────────────┐ │ Parent │ │ ┌───────┐ │ │ │ Child │ │ │ │ ┌─┐ │ │ │ │ │Grandchild│ │ │ └─┘ │ │ │ └───────┘ │ └─────────────┘ CSS selector: Parent Descendant Matches: Child, Grandchild
inside it, and that
can have inside it. This creates a tree-like structure where some elements are inside others.
elements that are inside a
is inside a
elements that are immediate children of a
elements inside a
elements inside a
elements, then checks if each has a
elements, then checks each one's ancestors to see if any is a
Selector: div p [Browser finds all <p> elements] → [For each <p>, check ancestors] ↓ [If any ancestor is <div>] → [Apply styles] ┌─────────────┐ │ <p> │ │ ↑ │ │ Ancestors: │ │ <section> │ │ <div> │ ← Match found └─────────────┘