TIL ":has" selector
POSTED ON:
TAGS: css organization
The :has() selector is so sweet!
Using this example: ul > li
Before :has(), the subject of a selector was always at the end.
If you wanted to edit the li item, you would do:
ul > li:hover or ul > li:not(.selected)
After :has():
ul:has(> li)
Some more examples:
.parent:has(.child) {...}
An example where a <section> element is the subject, but the selector only matches if one of the children has :focus-visible:
section:has(*:focus-visible) {...}
Related TILs
Tagged: css