-
Notifications
You must be signed in to change notification settings - Fork 719
[css-contain-3] Define a syntax for state-based container queries #6402
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
Agenda+ to defer this to L4 |
The CSS Working Group just discussed
The full IRC log of that discussion |
I don't know how to formulate this idea, but it would be nice to query state / behavior from things like Grid / Flexbox, particularly around things like:
The reason why I'm thinking about this is that there are tricks in flex-basis that people are using right now that create kind of an equivalent of container queries. The problem with something like flex-basis and flex-wrap is that you have a layout behavior applied at an unknown point / state. So you can't exactly use a container query to "capture" when the state / layout of that box / container changes. So, like, there's a Switcher layout in the Every Layout library that, when content size is below a certain width, using flex-basis magic, it will change a 3-column layout to a single column layout w/ 3 items. It would be nice to query when this happens, because the Flexbox doesn't "know" when that flex layout happens, and we're now in a single column. Because it's not based on a single property, and not necessarily a single "width", I really don't know how you would query it? But I just thought I'd put it out there. Here's a Codepen showing a Switcher with neither container nor media queries. https://codepen.io/matthewdean/pen/bGaKwRx |
I wonder.... if there's something like a syntax missing like a way to "push" state in CSS based on something... happening? I think it should be more like a way to push a state like header:sticky {
background: red;
} If you think about it, |
Imagine, for example, an accordion. Say it could do this. <div class="accordion">
This is some content
<button type="button" class="button">This is an accordion openerbutton>
<div class="hidden">
This is hidden content.
div>
div>
<style>
.accordion {
/** Or @state accordion(open, closed)? Allows multiple state vars and values? */
@state open;
}
.button:pressed {
/** Or toggle: accordion? */
toggle: state;
}
.hidden {
display: none;
}
.accordion:state(open) .hidden {
display: block;
}
style> Some kind of state system would prevent having to do radio button hacks with sibling combinator selectors to try to change a state of another element based on input of an initial element. |
@matthew-dean in terms of syntax and 'pushing state' to CSS, you might be interested in #6991 and the linked spec/explainer for our CSS Toggles proposal. I think it lines up pretty well with what you're suggesting in the last two comments. The idea of querying where an element lives in a grid/flex layout is interesting here, especially since it would require the limitation of a container. What I mean is: if we allowed an element to query it's own position in a layout, and then change the value of say |
Oh my god y'all are geniuses. A little different syntax, but yes!!
As to the other thing, yeah, I can't quite think of how this would work syntactically, but it feels like there are... I dunno, behaviors? States? Of CSS elements? That are defined / designed to be triggered by other properties. I just thought of a good allegory, which is a pseudo-element like See: this Stack Overflow question in which one of the answers to alternating color rows in CSS grid is basically to hack it by using a repeating gradient: https://stackoverflow.com/questions/58251569/coloring-every-other-row-using-css-grid |
I have started an explainer for state queries here: https://lilles.github.io/explainers/state_container_queries.html |
There is now also: |
The TAG review is closed. I would like to start working on a specification for scroll-based state queries. The states to be added at this point is:
Proposed resolutions:
Details for the proposed syntax can be found in the explainer, but is up for bikeshedding Details and rationale for using the HTML event loop modifications can also be found in the explainer. |
Is it available for detecting text overflow (ellipsis) state like #4123 ? |
The CSS Working Group just discussed
The full IRC log of that discussion |
Per resolution in [1]. Also use a single scroll-state container type instead of separate types for sticky and snap, including a new runtime enabled feature, implied by any enabled query feature, to check when recognizing the container type and parsing the scroll-state() function. [1] w3c/csswg-drafts#6402 (comment) Bug: 1445189, 1475231 Change-Id: I9acaf7570e9ee98157e31d0ff238bd0cd585dfad Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5075421 Commit-Queue: Rune LillesveenReviewed-by: Anders Hartvoll Ruud Cr-Commit-Position: refs/heads/main@{#1231311}
Resolved to move explainer from lilles.github.io in issue w3c#6402
Per resolution in [1], add scroll-state() as a query function to query sticky, snap, and overflow scroll states with a new container-type for scroll-state queries. [1] w3c#6402 (comment)
Per resolution in [1], add scroll-state() as a query function to query sticky, snap, and overflow scroll states with a new container-type for scroll-state queries. [1] w3c#6402 (comment)
Per resolution in [1], add scroll-state() as a query function to query sticky, snap, and overflow scroll states with a new container-type for scroll-state queries. [1] #6402 (comment)
In the discussion of what container features can be queried, there was interest in queries based on the "current state" of a container – such as whether a
position: sticky
container is currently "stuck" (displaced from its in-flow position), or whether the box is currently visible on screen.In the draft of CSS Containment L3 we currently allow a
state
value forcontainer-type
, but different states may require different types of containment (or none at all), so I don't think that single type value will work. We also need to define which states are supported initially, and how these states are queried in the@container
rule.For example, something along the lines of:
The text was updated successfully, but these errors were encountered: