Open Bug 1795622 Opened 3 years ago Updated 1 month ago

[css-contain-3] Support style() container queries

Categories

(Core :: CSS Parsing and Computation, enhancement)

enhancement

Tracking

()

Size Estimate M

People

(Reporter: bramus, Unassigned)

References

(Depends on 7 open bugs, Blocks 11 open bugs)

Details

(Keywords: parity-chrome, parity-safari, webcompat:platform-bug, Whiteboard: [platform-feature][webcompat:risk-high])

User Story

web-feature: container-style-queries
user-impact-score:40

Spec still a draft right now. Filed this issue so there’s something to track across all vendors.

Blocks: 1796166

Chrome has implemented style query of custom property values at version 111.
Webkit position is also supportive of the CSS variables use case: https://github.com/WebKit/standards-positions/issues/57#issuecomment-1691159042

Suggest to split the feature into variables usage and standard properties usage.
And Implement the CSS variables usage at first.
It maybe resolve some problems, even the another way for enviroment queries in shadow dom (Current supported with :host-context() in Chrome).

Update:
WebKit has enable Style queries by default WebKit/WebKit#24251

Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: [css-contain-3] Support style() queries → [css-contain-3] Support style() container queries
Depends on: 1874725
Depends on: 1887135
Depends on: 1902660
Blocks: 1914355
Blocks: 1924665
Depends on: 1928675
Depends on: 1930198
Depends on: 1920200
Depends on: 1929897

Very very sad that this is not supported yet. (Along with a few others.)

Hope to get support for it soon, because I use it as part of a "scroll-triggered animations" hack. There's no workaround for it, I think.

PS: Nice to see you here Bramus!

CSS WG has resolved to drop :host-context(), and suggest using container style queries to replace its use cases.

So is it possible to raise it priority?

(In reply to Arun Das from comment #5)

Hope to get support for it soon, because I use it as part of a "scroll-triggered animations" hack. There's no workaround for it, I think.

There is no need for style queries for scroll-triggered animations. See this demo I made back in 2023.


For anyone itching to try style queries in Firefox, you can now set the layout.css.style-queries.enabled flag to true in about:config. I've just used it to set different pseudo content values depending on a computed modulo value and it worked.

Size Estimate: --- → M
User Story: (updated)

Hello. I enabled the layout.css.style-queries.enabled flag and gave it a try, but it seems that switching custom properties based on state changes doesn't respond correctly.

Here's a sample.
https://codepen.io/tak-dcxi/pen/GgpojbL

In both Chrome and Safari, switching custom properties on hover works as expected.

Just wanted to drop by and state that I am also hoping for support for this to land in Firefox :)

I have tried setting the option layout.css.style-queries.enabled for my use-cases and that works without issues. I have found several use cases that I believe to be fairly nice (in a design system/component system use case)

  1. By having every flex container be a named container and setting custom properties indicating flex-flow attribute, I can create semantic classes for stretching vertical/horizontal, that will do what the user would expect. It is especially nice here as this would require different properties to be set depending on the flex-flow property, which is nicely handled here.
  2. Propagate information regarding the "size" of the current UI element being rendered, and make components that alter their size based on this. Of course this can be done by adding lots of custom properties indicating the size of various elements, but doing it this way I find much more composable.

In general I find it to be a nice way of passing "context" through the stylesheets much the same way as one would use context in react components, and style queries in container queries lets me avoid storing quite a bit of context in javascript and push it down to CSS instead.

I don't know if having these sorts of use cases are of value or not, hope it is not unwanted noise here.

Whiteboard: [webcompat:risk-high]
Whiteboard: [webcompat:risk-high] → [platform-feature][webcompat:risk-high]
User Story: (updated)
User Story: (updated)
You need to log in before you can comment on or make changes to this bug.