Styling Nested Elements with Descendant Selector
📖 Scenario: You are creating a simple webpage with a list of articles. Each article has a title and some paragraphs inside a section. You want to style only the paragraphs inside the sections differently from other paragraphs on the page.
🎯 Goal: Use the CSS descendant selector to change the text color of all paragraphs inside <section> elements to blue, while keeping other paragraphs black.
📋 What You'll Learn
Create an HTML structure with a
<main> element containing two <article> elements.Each
<article> should have a <h2> title and a <section> with two paragraphs.Add one paragraph outside the
<section> but inside the <article> to show difference.Write CSS using the descendant selector to style only paragraphs inside
<section> with blue text color.Paragraphs outside
<section> should remain black.💡 Why This Matters
🌍 Real World
Webpages often have nested content where you want to style only specific parts, like paragraphs inside a section, differently from others. Descendant selectors help you do this cleanly.
💼 Career
Understanding CSS selectors like descendant selectors is essential for front-end web developers to create well-structured, maintainable, and visually appealing websites.
Progress0 / 4 steps