Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
CSS

CSS: Fix Container Queries Ignoring a Percentage Width Parent

- 30.11.26 - ErcanOPAK

🎨 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: size only 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 auto or 0, that confirms the percentage chain is the actual problem, not the @container rule 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.

— UI Engineer

Related posts:

CSS Animations Cause Jank on Mobile

CSS Animations Cause Jank on Mobile

CSS: Use Transform for Animations and Layout

CSS: Use Transform for Animations and Layout

CSS: Fix a backdrop-filter Blur That Silently Disappears Because a Parent Element Has a transform Ap...

CSS: Fix a backdrop-filter Blur That Silently Disappears Because a Parent Element Has a transform Ap...

Views: 4
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

C#: Fix a Using Declaration Disposing in the Wrong Order
Git: Fix Autocrlf Rewriting a Binary File on Checkout

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 996 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 995 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 866 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 629 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com