pseudo-class
:only-child — CSS reference
Matches an element without other element siblings. It has one pseudo-class specificity component, unlike chaining first-child and last-child.
Formal Syntax & Structure
css syntaxcss
:only-childWorking Example
Example Snippetcss
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Selector lab</title><style>:where(.sample) { color: rgb(32, 32, 32); }p:only-child { color: rgb(0, 96, 80); }</style></head><body><div><p id="a" class="sample">A</p></div><div><p id="b" class="sample">B</p><span>Other</span></div></body></html>