在下面的示例中,我希望防止流散的孩子溢出父母。我不想为它指定宽度。我怎样才能做到这一点?
#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>
发布于 2017-09-21 06:17:56
您进入了最小宽度算法,其中flex项的min-width默认为auto,因此不允许它缩小到其内容以下。
您可以使用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>
或min-width: 0使其小于其内容
#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>
经过快速的跨浏览器测试(Chrome/Firefox/Edge/IE在Windows 10上),IE似乎需要word-break: break-all或overflow hidden
https://stackoverflow.com/questions/46336660
复制相似问题