Parent Selectors should have targets
See original GitHub issueWhen creating a Parent Selector rule, everything before the &
gets prepended to the outermost scope.
The feature could be greatly improved by allowing for “parent targeting”, where you could apply the parent selector to a specific parent (in the case where you have deeply nested selectors).
The syntax for this feature is probably the biggest hindrance, so I would love to start a discussion on the possibilities.
Issue Analytics
- State:
- Created 11 years ago
- Reactions:6
- Comments:118 (70 by maintainers)
Top Results From Across the Web
A Use Case for a Parent Selector
I've occasionally used Javascript to add my own HTML just to have some targets to style where a CSS parent selector would have...
Read more >Is there a CSS parent selector?
Parent selection is done via the pseudo-class :has() . For example, div:has(> .child) will select all <div> elements with a child having a...
Read more >Meet :has, A Native CSS Parent Selector (And More)
Like with most pseudo-classes, selectors can be chained to target child elements of a target element or adjacent element. /* Select image ...
Read more >Understanding the CSS parent selector :has()
The easiest way to describe :has() is as a parent selector. If we wish to target the parent element based on the content...
Read more >CSS :has(.parent-selectors)
Parent selectors select parent elements, right? They actually select grandparents and any matching ancestors as well. I haven't been the only ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m going to re-open this. We’ve seen variations on this idea (such as #1154), and I feel like there’s a possibility of a solution.
That is, there are times when people have a logical stack of elements, but don’t necessarily want to inherit the entire stack in their output.
Also, there are times when people want to inherit SOME of the stack, but not all of it.
I think we can all agree that we don’t want messy syntax, but I’d like to see a variety of ideas. As we’ve explored here, targeting by name seems problematic. But we could also target by level:
Basically, step “up” the inheritance tree to the level we want to inherit / append to the current selectors.
Or, something like, maybe “breaking” the inheritance and starting over, without having to move the class outside of the block. I dunno, like:
or, borrowing from the top example:
Both outputting:
Thoughts?
Since this issue is still open…
So far, trying to “select and insert” from parent selectors ends of being terribly complex. The “where” becomes quickly ambiguous.
I think the only workable solution if this feature were to happen would need to be something similar to “capturing” and “replacing” that’s used with regular expressions, where you define insertion points (in this example marked with
?
) that you use to manipulate output later.resulting in:
I’m not suggesting at all that that’s the right syntax, but any kind of “targeting” that’s been tried in this thread, either by index, or “scope level”, or named selector, just isn’t going to work without a precise target.
With insertion points, they have a left-to-right, top-to-bottom indexing order that is unambiguous. You can see where your thing will go, and can specify exactly what that thing is.
So any workable solution I believe will need to be some variation of this.