:has()
noun
say it: “KOH-lun HAZ” /ˈkoʊlən hæz/
A functional pseudo-class that styles an element by what it contains, such as li:has(:checked): a list item with a ticked checkbox inside. It is often called the parent selector.
What does :has() do?
:has() styles an element based on what is inside it, like "a card that contains an image". It is often called the parent selector.
.card:has(img) { padding-top: 0; }
form:has(:invalid) .submit { opacity: 0.5; }
In a sentence
- “With :has(), a song's whole row turns pink when its Like box is ticked, with no JavaScript.”
Level: Freelancer · More CSS terms at this level
Updated