-
Notifications
You must be signed in to change notification settings - Fork 717
[css-selectors-4] Selector for element with another element as ancestor #9130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
almost like that? /*/ use cases in post /*/
A P
/*/ description in post /*/
:is(A /*/ for A:root case /*/, :has(A)) P:not(:has(A)) |
Yeah I don't get the difference between If you just want to impose extra conditions, like |
Yup, Note tho that your first example:
won't match the selector because, due to the way HTML parsing is defined, inline elements are auto-closed by a
(Your second example works as intended, because This might be the source of your confusion! |
Actually, the HTML parser can place both <!DOCTYPE html>
<style>a p { border: solid green }</style>
<div>
<a href="http://example.org/">
<p>I match</p>
</a>
</div> |
Sorry, I think I didn’t explain the motivation for this. Obviously .aleph {
/* ... styles for .aleph ... */
& .beth {
/* ... styles for .aleph .beth ... */
& .gimel {
/* ... styles for .aleph .beth .gimel ... */
& .daleth {
/* ... styles for .aleph .beth .gimel .daleth ... */
&:within(a) {
/* special styles for .daleth when within a link, regardless of where the a
is in the tree of .aleph .beth .gimel */
} } } } } Afaict the only equivalent of this using the whitespace selector would be to write out the combinations by hand, and exiting the entire tree of selectors where the rest of the styles for a .aleph .beth .gimel .daleth,
.aleph a .beth .gimel .daleth,
.aleph .beth a .gimel .daleth,
.aleph .beth .gimel a .daleth {
/* special styles for .daleth within a link */
} This is long-winded and gets even more complicated if one imagines situations such as I also don’t see how |
Then you should use .aleph {
/* ... styles for .aleph ... */
& .beth {
/* ... styles for .aleph .beth ... */
& .gimel {
/* ... styles for .aleph .beth .gimel ... */
& .daleth {
/* ... styles for .aleph .beth .gimel .daleth ... */
a & { /* or `&:is(a *)` works too */
/* special styles for .daleth when within a link, regardless of where the a
is in the tree of .aleph .beth .gimel */
} } } } } Note that Unlike |
|
AFAIK that requirement was dropped in 02db7b2 |
Good to know! But it’s still present in browsers (and, afaict, in the PostCSS plugin I’m using as a stopgap to support Firefox) so for now I still need to follow it |
As a side note, Firefox 117 will ship with nesting and without the punctuation symbol requirement. Sebastian |
Yup, that restriction got dropped a while back and implementations will follow. We can't fix legacy implementations by adding new features, as by definition they're not being updated. ^_^ |
Uh oh!
There was an error while loading. Please reload this page.
Rough proposal: a pseudo-class, such as
p:within(a)
selectsp
elements which have ana
element anywhere in their ancestor tree.E.g. it would select any of the
<p>
elements here:But not this one:
While writing my first major design using CSS Nesting, this seemed like a missing feature, mainly for maintainability but also because truly accounting for all possible nesting situations to target the element wanted using regular selectors could be tricky within a complex nesting of selectors. A strong use case in particular (as implied above) is when elements might sometimes be inside links and sometimes not. This would allow them to be styled or restyled in a way more clearly indicating that they can be interacted with as links.
Link to spec: https://www.w3.org/TR/selectors-4/
The text was updated successfully, but these errors were encountered: