:only-child – pseudo-class

The :only-child pseudo-class selects element that is the only child of its parent.


element:only-child {
  /* ... */
:only-child {
  /* ... */

The :only-child selector is the same as :first-child:last-child or nth-child(1):nth-last-child(1). The :only-child has lower specificity.

See the Pen :only-child by majadc (@majadc) on CodePen.



Posted in CSS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.