CSS3 Selectors: The descendant selector

This entry is part 8 of 40 in the series CSS3 Selectors

Here we use article p as an example as shown below.

This is a descendant combinator.

We use article p making <p> the descendant of <article> element.

<!DOCTYPE html>
<html>
<head lang='en'>
    <meta charset='UTF-8'>
    <title>Codecrawl.com</title>
    <style>
        article p {
            font-family: sans-serif;
            color: blue;
            font-size: 125%;
        }
    </style>
</head>
<body>
<article>
    <h1>American Music</h1>

    <p>The different types of genre in American music.</p><!-- Child combinator targets this paragraph -->
    <section>
        <h2>Country</h2>

        <p>Taylor Swift</p><!-- Adjacent sibling combinator targets this paragraph -->
        <p>Carrie Underwood</p>
    </section>
    <p>Hard rock and metal</p><!-- Child combinator targets this paragraph -->
</article>
</body>
</html>

Try the CSS and you can see that all the <p> elements are affected.