:only-child (CSS selector)
Example
The following selector will match a
list item element if it’s the only list item in its parent
ol or ul element:
li:only-child {
⋮ declarations
}
Description
This pseudo-class matches an element if it’s the only child element of its parent.
Compatibility
| IE | 5.5 | None |
|---|---|---|
| 6.0 | None | |
| 7.0 | None | |
| Firefox | 1.0 | None |
| 1.5 | Buggy | |
| 2.0 | Buggy | |
| Safari | 1.3 | Buggy |
| 2.0 | Buggy | |
| 3.0 | Buggy | |
| Opera | 9.2 | None |
| 9.5 | Full |
In Firefox 1.5 and 2, this selector will continue to match an element even after sibling elements are inserted dynamically before or after it.
In Safari
versions up to and including 3, this selector behaves exactly like
:first-child.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

