CSS :only-child pseudo-class
- Página anterior :nth-of-type()
- Página siguiente :only-of-type
- Volver a la capa superior Manual de pseudoclases CSS
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 that fully supports this pseudo-class.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
- Página anterior :nth-of-type()
- Página siguiente :only-of-type
- Volver a la capa superior Manual de pseudoclases CSS