🎨 Fix Container Queries Ignoring a Percentage Width Parent
A container query measures the size a container-type: inline-size element actually resolves to, and if that container’s own width is itself a percentage of a parent whose size depends on its own children (a classic shrink-to-fit scenario), the browser can be left trying to query a container whose size was never unambiguously resolved first, so the query silently never matches any of its breakpoints.
🔎 The Problem
.card-wrap {
width: 60%; /* percentage of a parent with no explicit width */
container-type: inline-size;
}
@container (min-width: 400px) {
.card-title { font-size: 1.4rem; } /* never applies */
}
/* Parent has no width set, so .card-wrap's 60% has nothing
definite to resolve against before the container query runs */
✅ Fix: Give the Container’s Ancestor a Definite Size to Resolve Against
- Set an explicit width (or
width: 100%inside a parent that itself has a definite size) on the ancestor chain above the container, so the percentage has something concrete to compute from before the query evaluates. - Where the layout genuinely needs to shrink-to-fit, switch the container itself to
container-type: sizeonly if you also give it an explicit block-size — inline-size containers need a resolvable width specifically, not just ‘some size eventually’. - Use your browser’s DevTools to inspect the computed width of the container element directly; if it reports
autoor 0, that confirms the percentage chain is the actual problem, not the@containerrule itself.
A container query doesn’t fail quietly because the breakpoint is wrong — it fails because the container itself never got a real size to measure.




