In the sample below, I want to prevent the streched child from overflowing the parent. I do not want to specify a width for it. How can I accomplish that?
#flex-parent { display: flex; width: 200px; background: green; padding: 10px; }
#fixed-child { width: 20; background: red }
#stretched-child { background: yellow; word-wrap: break-word }
<div id="flex-parent">
<div id="fixed-child">
FIXED
</div>
<div id="stretched-child">
STREEEEEEEEEEEEEEEEEEEEEEEEEEEECHED
</div>
</div>
You hit the min-width algorithm, where the
min-width
of a flex item defaults toauto
and as such doesn't allow it to shrink below its content.You can use
word-break: break-all
Or
min-width: 0
to allow it to be smaller than its contentAfter a quick cross browser test (Chrome/Firefox/Edge/IE on Windows 10), it appears IE need either the
word-break: break-all
oroverflow hidden