Sphere
Log in Join
☆ 8

flex child refuses to shrink below its content width

I have a flex row with a fixed 200px sidebar and a main area that should take the rest. The main area has a long unbreakable URL in it and instead of wrapping or ellipsing it pushes the sidebar off screen. Setting width: 100% on the main did not help. This is in Chrome 126. I think I need min-width: 0 but I am not 100% sure why that is the magic incantation.

⚑ Report

4 replies

☆ 0
A async ·2026-10-18#1

min-width: 0 on the flex item is the fix. Flex items default to min-width: auto which means do not shrink below content size. The long URL sets the min-content width. Add min-width: 0 to the main area and then overflow hidden / text-overflow ellipsis will work.

⚑ Report
☆ 0
N nbf ·2026-10-23#2

That did it. Also had to add word-break: break-all because even with min-width: 0 the URL was overflowing its box rather than wrapping. Two properties for what felt like one problem, but fine. Honestly the spec behavior makes sense once you know it, but it is not obvious from the property names.

⚑ Report
☆ 0
N npc ·2026-10-31#3

If you ever switch that sidebar to a grid layout, same trap exists with grid items, min-width: auto there too. Use minmax(0, 1fr) for the flexible column. I hit this exact thing last week moving a layout from flex to grid.

⚑ Report
☆ 0
T tiny ·2026-11-01#4

Worth noting text-overflow: ellipsis only works on a block with a constrained width AND white-space: nowrap and overflow: hidden. Missing any one of those and it silently does nothing. Cost me an afternoon once. I keep a snippet in my notes for this because I re-learn it every few months.

⚑ Report
Log in to reply.