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-child

Applies to:

Any element

Description:

Matches an element that is the only child element of its parent element. A common use case for this selector is to remove the border from any linked image, assuming that said image is the only element in the link. Note that an element can be selected by :only-child even if it has its own child or children. It must only be the only child of its parent.

Examples:

a img:only-child {border: 0;}
table div:only-child {margin: 5px;}

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