CSS3 Selectors: Only-of-type

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

:only-of-type targets elements whose parent elements have no other children of the same type.

The <p> tag in <header> is targeted as it has only one <p> tag.

<!DOCTYPE html>
<html>
<head lang='en'>
    <meta charset='UTF-8'>
    <title>Codecrawl.com - HTML5</title>
    <style>
        p:only-of-type {
            color: blue;
        }
    </style>
</head>
<body>

<article>
    <header>
        <h1>Rod Stewart</h1>

        <p>21.06.2014</p>
    </header>
    <section>
        <h4>Sing It For Us Rod</h4>
        <p>Rod Stewart is one of the best-selling music artists of all time</p>

        <p>Having sold over
            100 million records worldwide.</p>
    </section>
</article>

</body>
</html>

Series Navigation<< CSS3 Selectors: nth-last-of-type
CSS3 Selectors: Pseudo-class :empty >>

Leave a comment

Leave a Reply