【发布时间】:2021-05-29 16:25:15
【问题描述】:
问题:在我当前的布局中,我的框具有基于标准的特定高度。我想使用列在该框/div 中显示数据,但是当我这样做时,到达第二列的项目会溢出父容器的宽度。 (见下图)
我正在寻找的结果:我希望元素占用父容器中所需的尽可能多的空间,可能只会在 Y 轴(垂直)上溢出。换句话说,我希望将文本换成多行。 (见下图)
代码:https://jsfiddle.net/sr9fj07m/
<div
style="
display: flex;
flex-direction: column;
height: 50px;
background-color: blue;
flex-wrap: wrap;
align-content: flex-start;
"
>
<div style="display: flex; flex-direction: row; align-items: center">
<div style="background-color: red">Other text here</div>
</div>
<div style="display: flex; flex-direction: row; align-items: center">
<div style="background-color: red">Another text here</div>
</div>
<div
style="
display: flex;
flex-direction: row;
align-items: center;
flex-shrink: 1;
"
>
<div style="background-color: aqua;">
random text goes here random text goes here random text goes here
random text goes here
</div>
</div>
</div>
如何实现?谢谢!
编辑: 我正在寻找的是一种解决方案,其中我没有硬编码的宽度,并且子项自动从上到下重新排列,包装成多列(flex-direction:column; flex-wrap:wrap),但不会溢出父宽度,并且所以将文本分成多行。
【问题讨论】: