0% completed
The descendant combinator (a single space) lets you select elements that are nested inside another element, regardless of how deeply they are nested. It works on all levels of descendants, not just immediate children.
ancestor descendant { property: value; }
Explanation:
descendant
) that are nested anywhere inside the ancestor
element.In this example, all <p>
elements inside a container with the class .wrapper
will have a specific text color. This shows how the descendant combinator targets all paragraphs nested inside the container.
Explanation:
.wrapper p
applies styles to every <p>
element inside .wrapper
, regardless of depth.<div>
, receive the green text color and font size.In this example, we use the descendant combinator to style all list items within a <section>
element. Even if the list items are inside nested <ul>
elements, they inherit the same styling.
Explanation:
section li
selects every <li>
element within the <section>
, including those nested inside other elements.These examples demonstrate how the descendant combinator uses a space between selectors to target elements nested within another element. By applying styles this way, you can simplify your CSS and maintain consistent design for elements that appear at various levels inside a container.
.....
.....
.....