CSS3 Selectors: The > selector

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

Here we use article > p.

This is a child combinator and <p> is a child 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 CSS3 and you will see that the <p> under <section> is untouched.

Series Navigation<< CSS3 Selectors: ID selectors
CSS3 Selectors: The descendant selector >>