-
Notifications
You must be signed in to change notification settings - Fork 708
[css-contain] Is there a use-case for querying explicit container selectors? #6176
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
I can't remember the exact use-cases for this, but given there were tons of these in my practice for skipping the stacking context etc, I'm pretty certain there would be use-cases for this (I'll try to remember/come up with such` use-cases if I'll have time). As a quick idea — I imagine most of such use-cases could be whenever we have something that escapes its own scope, but need to also need the grandparent's scope as well. Think of a content column, where something wants to escape the content grid and stretch among the whole width of the page — it would make sense to make the content column a container, so everything inside would scale properly, but then we wouldn't be able to make a child wider than that container, and at the same time to know the upper boundaries. (I can illustrate this example if I couldn't describe it properly, let me know!) Said that, the universal “nearest” container is a really nice default, as in most cases we'd want for our components to just work and adjust to the nearest container. However, for more complex scenarios we would want to skip some levels of containment when we know the selector of the thing we want to rely on. ( |
If explicit container selectors are a thing, in my opinion, the syntax should be a little different than the one you proposed, @mirisuzanne. The syntax you suggested surrounds the selector with brackets. This kind of syntax is only used for the conditions in media queries so far. One solution would be to just write the selector without brackets, i.e. Sebastian |
RE: use cases, the main one I'm thinking of that makes me hope this gets supported is this (although really this would call for immediate parent selector, perhaps just |
@mbacon-edocs I don't think it's possible that we would allow queries to create containers. You will always need both. But the author does still have options. Components can "carry their own container" as a wrapping element. But I also think it's totally reasonable to think of "containers" as a layout concern (not attached to the component), and "queries" as a component concern (responding to space available in the layout). Queries are about responding to context, after all. I do think there are several reasons we do want to allow specifying the container still:
In working on a more explicit syntax for containment, I also proposed a main {
container-type: inline-size style;
container-name: layout-area;
}
@container layout-area (inline-size > 30em) { … } |
@mirisuzanne Yes of course, I was concerned about having to define containers around all components in case they wanted to use container queries, but you're right, they'll have to just have a wrapping element to be defined as one which should fix it. Also on the topic of selector(s), my 2 cents, I think having it optional (specific when defined, or undefined means nearest parent container) would be best. I also like the naming concept (whether enforced or optional vs typical selectors) as it feels in keeping with the concepts in CSS grid areas. |
@dbaron's original proposal included an explicit selector for the container to be queried:
In part, that's explained as a way to implement scope as part of containment. But I'm not sure those two features always make sense together, and all the CQ use-cases I've encountered so far rely on:
Requiring an explicit selector would make those use-cases more difficult, since it makes the query less modular, and potentially less relevant to immediate context. That said, if the selector is useful in some cases, we could consider allowing it as an optional syntax:
Aside:
I can imagine some hypothetical use-cases, though most would be solved by using descendant selectors (or
@scope
) along with container queries. In those cases it might be syntax sugar, but doesn't provide much. More important would be any use-cases where an author wants to "skip over" the most immediate container context, and query a container farther up in the DOM tree. Do those use-cases exist?The text was updated successfully, but these errors were encountered: