Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

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

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
CSS

CSS: Fix an aspect-ratio Box Collapsing When Content Overflows

- 18.11.26 - ErcanOPAK

🎨 CSS: Fix an aspect-ratio Box Collapsing When Content Overflows

aspect-ratio sets a preferred size relationship between width and height, but it isn’t a hard clamp on the box — other layout rules can still win. Inside a flex container, a flex item’s default min-height: auto lets its content push the box taller than the ratio alone would produce, and if the content also overflows without any overflow handling, the box can end up looking like it never respected the ratio at all, when really the ratio was respected right up until something else overrode it.

🔎 The Problem

.thumb {
  aspect-ratio: 16 / 9;
  display: flex;
  /* default min-height: auto on a flex item lets content
     stretch the box past the ratio's intended height */
}
.thumb p {
  margin: 0; /* long caption text still forces extra height */
}

✅ Fix: Give the Content Somewhere to Go Besides Growing the Box

  • Add min-height: 0 (or min-width: 0 for row layouts) on the flex item so its content stops being able to override the ratio-derived size through the default auto minimum.
  • Set overflow: hidden (or a scrollable overflow value, if that’s the intent) on the ratio box so content that genuinely doesn’t fit is contained or scrollable instead of silently stretching the box.
  • If the box sits inside a grid or flex parent using stretch alignment, set align-self: start (or the equivalent) on it so the parent’s stretch behavior doesn’t compete with the ratio you’ve already declared.

🚨 Why This Is Dangerous

  • A ratio box that silently grows past its intended height on long content can break a card grid’s alignment across an entire row, since every sibling box keeps its correct height while just the one with overflowing content stretches.

aspect-ratio tells the box what shape it would like to be, not what shape it’s guaranteed to be — content, min-height, and the parent’s layout mode all still get a vote.

— UI Engineer

Related posts:

CSS: Fix a Subgrid That Ignores Its Parent Grid's Track Sizes Because display: subgrid Was Only Set ...

CSS: Fix a Subgrid That Ignores Its Parent Grid's Track Sizes Because display: subgrid Was Only Set ...

CSS: Fix an initial-letter Drop Cap Overlapping the Line Below It Because the Property Ignores the P...

CSS: Fix an initial-letter Drop Cap Overlapping the Line Below It Because the Property Ignores the P...

Create Smooth Page Transitions with CSS View Transitions API (No JavaScript)

Create Smooth Page Transitions with CSS View Transitions API (No JavaScript)

Views: 3

Post navigation

Photoshop: Fix the Color Picker Clamping a Custom Swatch’s Hue
SQL Server: Fix a View Returning Stale Data After a Schema Change

Leave a Reply Cancel reply

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

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,056)
  • Get the User Name and Domain Name from an Email Address in SQL (982)
  • How to add default value for Entity Framework migrations for DateTime and Bool (980)
  • Get the First and Last Word from a String or Sentence in SQL (859)
  • How to select distinct rows in a datatable in C# (856)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (657)
  • Add Constraint to SQL Table to ensure email contains @ (612)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (548)
  • Find numbers with more than two decimal places in SQL (477)

Recent Posts

  • HTML5: Fix a datalist Suggestion List Not Filtering as You Type
  • WordPress: Fix a Custom Field Resetting After Every Autosave
  • Docker: Fix a Healthcheck Marking a Container Unhealthy Too Soon
  • Windows 11: Fix Voice Typing Placing Punctuation in the Wrong Spot
  • Git: Fix a Stash Pop Conflicting With Unrelated Untracked Files
  • Photoshop: Fix the History Brush Reverting Past a Resize Step
  • SQL Server: Fix a View Returning Stale Data After a Schema Change
  • CSS: Fix an aspect-ratio Box Collapsing When Content Overflows
  • Photoshop: Fix the Color Picker Clamping a Custom Swatch’s Hue
  • JavaScript: Fix Array.sort Reordering Equal Items Unexpectedly

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,056)
  • Get the User Name and Domain Name from an Email Address in SQL (982)
  • How to add default value for Entity Framework migrations for DateTime and Bool (980)
  • Get the First and Last Word from a String or Sentence in SQL (859)
  • How to select distinct rows in a datatable in C# (856)

Recent Posts

  • HTML5: Fix a datalist Suggestion List Not Filtering as You Type
  • WordPress: Fix a Custom Field Resetting After Every Autosave
  • Docker: Fix a Healthcheck Marking a Container Unhealthy Too Soon
  • Windows 11: Fix Voice Typing Placing Punctuation in the Wrong Spot
  • Git: Fix a Stash Pop Conflicting With Unrelated Untracked Files

Social

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