Encountered the min-width algorithm, which sets the default min-width
of a flex item to auto
, preventing it from shrinking below its content.
One solution is to use word-break: break-all
#flex-parent {
display: flex;
width: 200px;
background: green;
padding: 10px;
}
#fixed-child {
width: 20;
background: red
}
#stretched-child {
background: yellow;
word-wrap: break-word;
word-break: break-all;
}
<div id="flex-parent">
<div id="fixed-child">
FIXED
</div>
<div id="stretched-child">
STREEEEEEEEEEEEEEEEEEEEEEEEEEEECHED
</div>
</div>
Alternatively, use min-width: 0
to allow the item to be smaller than its content
#flex-parent {
display: flex;
width: 200px;
background: green;
padding: 10px;
}
#fixed-child {
width: 20;
background: red
}
#stretched-child {
background: yellow;
word-wrap: break-word;
min-width: 0;
}
<div id="flex-parent">
<div id="fixed-child">
FIXED
</div>
<div id="stretched-child">
STREEEEEEEEEEEEEEEEEEEEEEEEEEEECHED
</div>
</div>
Following a brief cross-browser test (Chrome/Firefox/Edge/IE on Windows 10), it seems IE requires either word-break: break-all
or overflow:hidden