CSS :only-child Pseudo-class
Example
Specify a style for any <p>, <li>, and <b> element that is the only child of its parent:
p:only-child {
background-color: red;
}
li:only-child {
color: salmon;
}
b:only-child {
color: green;
}
Try it Yourself »
Definition and Usage
The CSS :only-child
pseudo-class
is used to select and style any element that is the only child of its parent.
Version: | CSS3 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the pseudo-class.
Pseudo-class | |||||
---|---|---|---|---|---|
:only-child | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
CSS Syntax