The issue that usually stops selectors like this from happening is that most of CSS is designed so browsers can display pages as they stream in from the network. (Usually called “single flow,” or something.) If you had code like this, for example:
And while receiving the HTML from the network,
<li class="featured"> came in, the browser would have to lay out and paint that part of the document again.
That said, this isn’t as true as it used to be.
table-layout: auto and Flexbox requires more than one layout pass, and so do other proposed advanced layout modules. So this might be more plausible to implement than the last time CSS Selectors was being drafted.
Observation of those in the wild has shown us some problems, though:
The layout can jump all over the place during loading, disorientating the user. And considering scripted DOM changes, user actions like resizing, and animations, it would be trivial for the layout to start thrashing around in deep corners of a large site’s codebase.
Or like automatic table layout, the browser doesn’t render anything until that particular area is done, which is also terrible.
Layout calculations can very easily get complex and slow; it makes it really easy for authors to write horribly-performing CSS that they might not notice on beefy desk/laptops. (This isn’t far-fetched; see the saga of
The CSS Working Group is pretty staunch about withholding powerful features that are easy to shoot yourself in the foot with. It sucks to hear it, but the language was designed from day one to limit the developer’s powers for better user experience on average. The expectation was most CSS would be written badly, and that’s pretty true. If 50% of all developers are below average, given the scale of the Web, that’s a lot of below-average CSS, and a lot of surface area for unintended disaster. By limiting how much a developer can do, it also limits how bad a developer can screw up.
To be clear, I would love this selector myself, I’m just pointing out why this sort of thing hasn’t succeeded in the past.
We just need to figure out how to solve these issues, kind of like how Container Queries evolved out of Element Queries. Maybe we could steal some concepts from GSS, since constraint-based layout usually has safety valves built in.