CSS :only-child Pseudo-class
- Previous Page :nth-of-type()
- Next Page :only-of-type
- Go Up One Level CSS Pseudo-class Reference Manual
Definition and Usage
CSS :only-child
Pseudo-classes are used to select and set the styles of any element that is the only child of its parent element.
Example
Specify styles for any <p>, <li>, and <b> element that is the only child of its parent element:
p:only-child { background-color: red; } li:only-child { color: salmon; } b:only-child { color: green; }
CSS Syntax
:only-child { css declarations; }
Technical Details
Version: | CSS3 |
---|
Browser Support
The numbers in the table specify the first browser version to fully support the pseudo-class.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
- Previous Page :nth-of-type()
- Next Page :only-of-type
- Go Up One Level CSS Pseudo-class Reference Manual