Full answer
A flex item has min-width: auto by default. For most items that means "never shrink below the width of its content". If the content is a long unbroken string or text with white-space: nowrap, the item refuses to shrink, and it pushes the row wider than its container.
The fix is to allow the item to shrink with min-width: 0 (or any overflow value other than visible, which changes the automatic minimum to zero). Then add the overflow behaviour you want, such as an ellipsis.
In the first row, the title stays as wide as its text and pushes the Open button out of the row. In the second row, the title shrinks to 240px (the 300px of room inside the row minus the 60px button), the text is cut with an ellipsis, and the button stays inside.
The same problem happens vertically in column layouts (min-height: auto) and with grid items. In a grid, the equivalent fix is minmax(0, 1fr) instead of plain 1fr, because 1fr means minmax(auto, 1fr).
When you meet an unexpected overflow in flex or grid, open DevTools, select the item and check its computed width against its content. This bug is behind many reports that a layout breaks when a name or title is long.
<style>
body { margin: 0; font: 16px sans-serif; }
.row { display: flex; width: 300px; margin-bottom: 12px; border: 1px solid #999; }
.title { flex: 1; white-space: nowrap; background: #eef; }
.row.fixed .title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.action { flex: 0 0 60px; background: #fe9; }
</style>
<div class="row" id="broken">
<div class="title" id="t1">Introduction_to_Data_Structures_and_Algorithms_Lecture_Notes.pdf</div>
<button class="action" id="a1">Open</button>
</div>
<div class="row fixed" id="fixed">
<div class="title" id="t2">Introduction_to_Data_Structures_and_Algorithms_Lecture_Notes.pdf</div>
<button class="action" id="a2">Open</button>
</div>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Flex items default to min-width: auto and refuse to shrink below content.
- min-width: 0 allows the item to shrink.
- Ellipsis needs overflow: hidden, white-space: nowrap and text-overflow: ellipsis.
- The same cause applies to min-height in column layouts.
- In grid, plain 1fr has an automatic minimum; use minmax(0, 1fr).
Common mistakes
- adding overflow: hidden to the container and not the item. The container hides the overflow but the item layout is still wrong.
- using fixed pixel widths on items to avoid the problem. They break again at another screen size.
Follow-ups
- how is the same bug fixed in Grid?
- Why does 1fr in grid sometimes overflow?
- What other property can change the automatic minimum size of a flex item?
Tips
- For ellipsis, remember the trio: overflow: hidden, white-space: nowrap and text-overflow: ellipsis, plus min-width: 0 on a flex item.
- Say the cause (min-width: auto) before the fix. Many answers give only the fix.
- Mention checking computed widths in DevTools when you find unexpected overflow.