-
Notifications
You must be signed in to change notification settings - Fork 707
Allow applying style rules to the container itself (especially with style querries) #10744
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
This has some overlap with my proposal to add an I agree that needing to create otherwise useless elements in markup, purely for style queries is an anti-pattern. Maybe even both proposals are useful for subtly different cases?
|
Indeed, that looks pretty similar (btw, sorry about that I couldn't find it)! @container style(--color: pink) {
:container.foo {
background-color: pink;
}
} |
Correct :) The subtle differences I was referring to are more with this kind of case: <div class="parent" style="--color: pink">
<div class=child>
hello
</div>
</div> @container style(--color: pink) {
:container {
background-color: rgb(from pink r g b / 0.3);
}
} Would <div class="parent" style="--color: pink">
<div class=child>
hello
</div>
</div> .parent {
container-name: a-container;
}
@container a-container style(--color: pink) {
:container {
background-color: rgb(from pink r g b / 0.3);
}
} Here it should only match With In that way a |
In your case I would expect only the parent to be selected as, currently (if I'm not wrong) |
I cannot test properly my theory (the |
I don't think it's viable for Unlike There is no way to select elements based on their styles, since selection has to happen in order to style the elements. So at the point where we would try matching But styles are resolved outside-in – parent styles have to resolve in order for inheritance on child elements – so it is possible (after selection) to make a child style conditional on a parent/ancestor style. This is why container queries didn't use a selector syntax in the first place. |
@mirisuzanne |
@PupilTong I'm not saying it would be impossible to have a self-styling feature - that is what |
@mirisuzanne Thanks! Now I understood the reason about it. Actually What we need (#10190) is something like selecting the direct children of a container. Will a |
In addition, we could still do this: @container style(--use-bg-color: true) {
* {
background-color: var(--bg-color);
}
}
@container not style(--use-bg-color: true) {
* {
background-color: initial;
}
} |
Like
:scope
in@scope
blocks or also:host
in web components, adding a:container
in@container
especially with style querries would be an amazing addition. It would let us style a container itself based on any style rule/ custom properties applied to it without the need for wrapping it inside of another component that would be needed only for that.The text was updated successfully, but these errors were encountered: