O'Reilly logo

CSS Pocket Reference, 4th Edition by Eric A. Meyer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

:only-of-type

Applies to:

Any element

Description:

Matches an element that is the only child element of its type to its parent element. Note that an element can be selected by :only-of-type even if it has its own child or children of its own type (such as divs within a div). It must only be the only child of its type to its parent.

Examples:

p em:only-of-type {font-weight: bold;}
section article:only-of-type {margin: 2em 0 3em;}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required