:has()

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2021 Mar 26 7:33
Editor
Edited
Edited
2023 Oct 23 5:47
Refs
Refs

nesting cannot be done

 
 
 
 
Selecting previous siblings with CSS :has()
Selecting a previous sibling was for long impossible, but is now a breeze with the has() pseudo-class
Is there a CSS parent selector?
CSS4 will be fancy if it adds some hooks into walking backwards. Until then it is possible (though not advisable) to use checkbox and/or radio to break the usual way that things are connected, and through that also allow CSS to operate outside of its normal scope... ...
Is there a CSS parent selector?
State of CSS 2022
Web styling features of today and tomorrow, as seen at Google IO 2022, plus some extras. The year 2022 is set to be one of CSS's greatest years, in both features and cooperative browser feature releases, with a collaborative goal to implement 14 features!
State of CSS 2022
The CSS :has() selector is way more than a "Parent Selector"
Safari Technology Preview 137 just dropped, with unflagged support for CSS :has(). Often dubbed "the parent selector", CSS :has() is way more than that ... ~ As per selectors-4 specification: The :has() CSS pseudo-class represents an element if any of the selectors passed as parameters match at least one element.
The CSS :has() selector is way more than a "Parent Selector"

Usage

Thread by @jh3yy on Thread Reader App
Future CSS Tip! 🔮 Use :has() to power micro-interactions and theme 😎 No JavaScript. Animations powered by state 🚀 .group:has(:invalid) { animation: shake 0.5s; } form:has(.email:valid):has(.password:valid) .submit { --color: green; } Demo link below 👇 Here's that @CodePen link!
Thread by @jh3yy on Thread Reader App
 
 
 

Recommendations