Meet `:has`, A Native CSS Parent Selector

The reasons that are often cited that make container queries difficult or impossible is things like infinite loops—e.g. changing the width of an element, invalidating a container query, which changes the width again, which makes the container query take effect, …


The post Meet `:has`, A Native CSS Parent Selector appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

The reasons that are often cited that make container queries difficult or impossible is things like infinite loops—e.g. changing the width of an element, invalidating a container query, which changes the width again, which makes the container query take effect, etc. But that was solved with containment. A “parent selector”, or :has as it is now been officially dubbed (I like it, that’s how jQuery rolled, although Adrian pointed out a tweet noting that it’s more versatile), has traditionally had similar problems. Things like requiring “multiple pass” rendering which is too slow to be acceptable.

Brian Kardell says:

Primarily, even without :has() it’s pretty hard to live up to performance guarantees of CSS, where everything continue to evaluate and render “live” at 60fps. If you think, mathematically, about just how much work is conceptually involved in applying hundreds or thousands of rules as the DOM changes (including as it is parsing), it’s quite a feat as is.

Engines have figured out how to optimize this based on clever patterns and observations that avoid the work that is conceptually necessary – and a lot of that is sort of based on these subject invariants that has() would appear to throw to the wind.

The fact that there is a spec now is super encouraging, and that it has Igalia’s eye on it. Apparently, some of the performance problems have either been surmounted or, through testing, determined to be negligible enough to remain a shippable feature.

Adrian Bece digs into it all!

The team at Igalia has worked on some notable web engine features like CSS grid and container queries, so there is a chance for :has selector to see the light of day, but there is still a long way to go.

What makes relational selector one of the most requested features in the past few years and how are the developers working around the missing selector? In this article, we’re going to answer those questions and check out the early spec of :has selector and see how it should improve the styling workflow once it’s released.

Let’s cross our fingers. I’ve been watching this for 10 years and trying to document use cases.

Direct Link to ArticlePermalink


The post Meet `:has`, A Native CSS Parent Selector appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-07-12T19:45:00+00:00) Meet `:has`, A Native CSS Parent Selector. Retrieved from https://www.scien.cx/2021/07/12/meet-has-a-native-css-parent-selector/

MLA
" » Meet `:has`, A Native CSS Parent Selector." Chris Coyier | Sciencx - Monday July 12, 2021, https://www.scien.cx/2021/07/12/meet-has-a-native-css-parent-selector/
HARVARD
Chris Coyier | Sciencx Monday July 12, 2021 » Meet `:has`, A Native CSS Parent Selector., viewed ,<https://www.scien.cx/2021/07/12/meet-has-a-native-css-parent-selector/>
VANCOUVER
Chris Coyier | Sciencx - » Meet `:has`, A Native CSS Parent Selector. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/12/meet-has-a-native-css-parent-selector/
CHICAGO
" » Meet `:has`, A Native CSS Parent Selector." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/07/12/meet-has-a-native-css-parent-selector/
IEEE
" » Meet `:has`, A Native CSS Parent Selector." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/07/12/meet-has-a-native-css-parent-selector/. [Accessed: ]
rf:citation
» Meet `:has`, A Native CSS Parent Selector | Chris Coyier | Sciencx | https://www.scien.cx/2021/07/12/meet-has-a-native-css-parent-selector/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.