-
Notifications
You must be signed in to change notification settings - Fork 685
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
[css-conditional] Element queries #10509
Comments
Re-targeted this against css-conditional, since container queries are being moved over there, and out of the contain spec. If we can do something like this, it would be useful. I'd be curious about trying to integrate it more into container queries - but I'm not sure if that only makes it more complicated. The primary limitation here that CQs solve is the potential for dependency loops. As I understand it, that's easier to resolve property by property (with the .foo {
--color: pink;
background-color: blue;
@element style(--color: pink) {
--color: not-pink; /* certainly this is invalid */
background-color: pink; /* but is this applied? */
}
} I imagine we can come up with an answer to that question, as far as feature design goes. But I'm not sure how hard it is to implement. |
My thinking: we already can have multiple ways to have inline conditionals: https://lea.verou.me/blog/2024/css-conditionals-now, and some of them working almost as “block”-level ones as well (the Of course, that is if we'd treat them the same.
If we were to work around such conditionals with inline ones, any IACVT variables used for that condition will result in everything inside becoming also IACVT. Then, if we will have something like Interestingly, only the element itself will be affected in this way: any nested styles could already be expressed as container queries, which properly handle reverting styles when not applying. .foo {
--color: pink; /* becomes IACVT */
@element style(--color: pink) {
--color: not-pink;
& .bar {
background-color: pink;
}
}
} In the above block, authors could separate the Thus, my proposal is: if an element query creates a loop in a condition, all affected styles on the element itself should be treated as |
I wonder if there would be a path for adding something like @bkardell's @kizu You're suggesting that de-sugared
That sounds reasonable to me, though I'm not sure if that's already part of I think it's probably good that your proposal would invalidate the entire block – so the rule block is all-or-nothing – but doing it at computed value time does seem rough unless we have something like Other query types (like size queries) might be a bit more complicated? We would have to disallow changing anything that could impact size in any way – which isn't always a clear or concise restriction. |
Container queries allow us to query a container for specific conditions, including values of custom properties through
style()
queries.But they do not allow us to query the element itself.
In #10064 there is a proposal for inline conditions that do allow setting values conditionally when an element has a specific value. Implementers indicated that this would be possible
Can we have the same as an
at rule
?I am assuming that this needs to be highly restricted as explained in #10064 (only
style()
queries with custom properties?)This example would result in a
pink
background on any element with class.foo
when it also has--color: pink
.Nested vs. not nested gives interesting possibilities:
Benefits I see to this syntax:
The text was updated successfully, but these errors were encountered: