Level Up Your CSS Skills With The :has() Selector — Smashing Magazine
Using :has() gives us the ability to “look ahead” with CSS and style a parent or ancestor element. Then, we can broaden the selector to target one or more siblings or children. By considering element states or positions, we can style nearly any combination of elements as unique singles or ranges.
Note: At present, support for :has() is rising, with it being available as of Safari 15.4 and Chrome/Edge 105. It is also behind a flag in Firefox as of version 103. Until full support is available, check out this tip for supporting :has today from Bramus Van Damme.
How :has() Works With Combinators And Pseudo-Classes
To best understand how the advanced selectors we’ll be creating work, we’ll quickly review the most relevant combinators and pseudo-classes.
A “combinator” is a special character that denotes the type of relationship between selector parts. Here are the core combinators to know:
- space character: the descendent combinator matches a direct or nested child;
- >: the direct child combinator matches only top-level, un-nested children;
- +: the adjacent sibling combinator matches only the very next sibling;
- ~: the general sibling combinator matches one or more siblings following the base selector.
source: https://news.oneseocompany.com/2023/01/23/level-up-your-css-skills-with-the-has-selector-smashing-magazine_2023012339571.html
Your content is great. However, if any of the content contained herein violates any rights of yours, including those of copyright, please contact us immediately by e-mail at media[@]kissrpr.com.