CSS3 Selectors: The + selector

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

Here in this example, we use h2 + p.

This is an adjacent sibling combinator.

It selects an element <p> immediately preceded by a <h2> element.

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

    <p>The different types of music genre in America.</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>
    <h1>Hard rock and metal</h1>

    <p> Nirvana has come to be regarded as one of the most influential and important rock bands of the modern era.</p>
    <!-- Child combinator targets this paragraph -->
</article>
</body>
</html>