Dev Overflow Logo

Dev Overflow

Global search

Search across questions, answers, users and tags.

Loading...
save

CSS: why does my flex child overflow instead of shrinking?

clock icon

asked 2 months ago

message icon

2

eye icon

1.3K

A long unbroken string in a flex child blows out the layout and produces a horizontal scrollbar, even with overflow: hidden on the parent.

1<div class="flex">
2 <div class="flex-1">averyveryverylongunbrokenstring...</div>
3</div>
1<div class="flex">
2 <div class="flex-1">averyveryverylongunbrokenstring...</div>
3</div>

2 Answers

Flex items default to min-width: auto, which means "never shrink below my content's intrinsic size". An unbreakable string has a large intrinsic size, so the item refuses to shrink and overflows.

Override it on the child:

1.flex-1 { min-width: 0; }
1.flex-1 { min-width: 0; }

In Tailwind that is min-w-0. The same applies vertically in a column flex container with min-h-0, which is the usual reason a scrollable panel inside a flex column won't scroll.

If the content is genuinely unbreakable text rather than a layout bug, pair it with break-words or truncate — min-w-0 lets it shrink, but you still have to say what happens to the overflowing text.

1

of 1

Write your answer here

Introduce the problem and expand on what you've put in the title.

Top Questions