Description
@dbaron's original proposal included an explicit selector for the container to be queried:
@container <selector> (<container-media-query>)? {
// ... rules ...
}
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:
- Querying the most immediate available space
- Being able to move components between containers
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:
@container (<selector>)? (<container-media-query>)? {
// ... rules ...
}
Aside:
- I imagine it only works when the selectors inside the query are descendants of the container selector.
- What if a selector is provided without any other query conditions? Is that allowed? It starts to look a lot like scope…
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?