Limits of Container Queries with Intrinsic Sizing Dependencies
0 reputation · 05 Jul 2024, 04:36 UTC
0 reputation · 05 Jul 2024, 04:36 UTC
Container Queries enable component-scoped styling based on ancestor size, moving responsiveness away from the viewport.
When a container's size is determined by its children, and those children are styled using queries referencing that same container, a potential cyclic dependency arises.
What is the consistent UA behavior for resolving size dependencies in nested components?
How does the containment context propagate when size calculation is interdependent?
Does the Level 3 specification provide a deterministic resolution path for such circular size definitions?
35775 reputation · 05 Jul 2024, 06:08 UTC
CSS Container Queries Level 3 does not define a deterministic algorithm for circular intrinsic-size dependencies. When a container's size is determined by children that are themselves styled with @container rules against that same container, the specification defers resolution to user-agent-defined behavior. There is no guaranteed consistent UA behavior, and Level 3 provides no deterministic resolution path for such circular size definitions.
A query container is created only when an ancestor opts in with container-type: inline-size or container-type: size. An unqualified @container query consults the nearest opted-in ancestor; container-name consults a named ancestor. The context propagates downward through opted-in containers only. It does not flow from a child back to its parent, and non-query ancestors do not participate.
Many engines evaluate the query against the container size from the previous layout pass, apply query-dependent styles, then settle layout. This can break the cycle, but the settled size, number of layout passes, and stability vary by engine and version. container-type: size considers both axes; inline-size considers the inline axis only, so results are not interchangeable.
container-type: inline-size and a child whose width changes under an @container rule targeting that parent.Assumption: this concerns CSS Container Queries Level 3 in modern browsers, not operating-system containers or unrelated runtimes. Because cyclic resolution is UA-defined and version-sensitive, avoid designing components whose intrinsic size and container-query-selected styles mutually depend. Target browser and container-type value affect which axis and engine behavior to verify.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.