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 Text Inside a Flex Item Overflowing Past a Fixed-Width Sibling Because Flex Items Default to a Minimum Width of Their Content

- 29.10.26 - ErcanOPAK

🎨 Fix Text Inside a Flex Item Overflowing Past a Fixed-Width Sibling Because Flex Items Default to a Minimum Width of Their Content

Every flex item’s computed min-width defaults to auto, which resolves to the size of its content’s longest unbreakable run – not zero – so a flex-basis or flex-grow value is only ever a target the item shrinks toward, never a hard ceiling it’s forced below. A long unbroken word keeps the item wider than its flex-basis no matter how much flex-shrink you give it, pushing it past a fixed-width sibling instead of wrapping.

🔎 The Problem

.row { display: flex; }
.sidebar { width: 240px; flex-shrink: 0; }
.main    { flex: 1 1 auto; }   /* expected to shrink to fit */

Computed widths at a narrow viewport:
  .sidebar: 240px (correct, flex-shrink: 0)
  .main:    content's intrinsic min-width (a long URL or
            unbroken string), NOT the flex-basis - overflows
            past .sidebar's right edge instead of wrapping

Root cause: .main never received an explicit min-width,
so its default of min-width: auto resolves to 'as wide as
my longest unbreakable content needs,' overriding flex-
shrink entirely for that one dimension.

✅ Fix: Override the Default min-width Explicitly

  • Set min-width: 0 on any flex item that should be allowed to shrink below its content’s intrinsic size – this is the single line that actually unlocks flex-shrink for text and block content.
  • For a flex item containing a long unbreakable string specifically, pair min-width: 0 with overflow-wrap: anywhere (or word-break: break-word) on the inner text so it wraps instead of just clipping once it’s allowed to shrink.
  • Apply the same min-width: 0 fix to nested flex or grid containers inside the item too – a child flex container inherits this same default independently and can reintroduce the overflow one level deeper.

🚨 Why This Is Dangerous

  • Setting min-width: 0 globally on every flex item can hide a genuine layout bug elsewhere by letting content shrink to unreadable widths silently – apply it to the specific item that needs to shrink, not as a blanket reset.

flex-shrink says how eagerly an item gives up space – min-width: auto is the floor that decides whether it’s even allowed to.

— UI Engineer

Related posts:

CSS: Use Border Radius for Rounded Corners

CSS: Use Border Radius for Rounded Corners

CSS: Fix a Sticky Header That Silently Stops Sticking Partway Down the Page Because an Ancestor's Ov...

CSS: Fix a Sticky Header That Silently Stops Sticking Partway Down the Page Because an Ancestor's Ov...

CSS: Use Container Queries for True Component-Based Responsive Design

CSS: Use Container Queries for True Component-Based Responsive Design

Views: 9

Post navigation

JavaScript: Fix a Proxy-Wrapped Object Losing Its Custom Methods After It’s Passed Through JSON.stringify and Rebuilt With JSON.parse
C#: Fix a Lock Statement Protecting the Wrong Object Because Two Unrelated Methods Locked on a Boxed Value Type

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,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • 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 (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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