html - 如何在其宽度内适应 CSS flex 内容?
问题描述
我有 3 个DIV
组件,其中:
.child-left
: 将其内容在屏幕左侧对齐.child-center
: 将其内容与屏幕中心对齐.child-right
: 将其内容与屏幕右侧对齐
但是,当内容(或文本)变得非常长时.child-center
,即使它有自己的内容,内容也会相互溢出width
。请看下面的截图:
我想知道:
- 为什么里面的内容(
Long text...
).child-center
不适合宽度? - 如何通过最小的更改来解决问题?(我想继续使用
display: flex
,我不想使用text-align: center
)
我想要实现的是:
请帮帮我!
代码:
.parent {
display: flex;
align-items: center;
width: 100%;
}
.child-left {
display: flex;
justify-content: flex-start;
width: 20%;
background-color: green;
white-space: nowrap;
}
.child-center {
display: flex;
justify-content: center;
width: 60%;
background-color: red;
white-space: nowrap;
}
.child-right {
display: flex;
justify-content: flex-end;
width: 20%;
background-color: yellow;
white-space: nowrap;
}
<div class="parent">
<div class="child-left">
<span>11111111111111111111111111</span>
</div>
<div class="child-center">
<span>Long text Long text Long text Long text Long text Long text Long text Long text Long text</span>
</div>
<div class="child-right">
<span>22222222222222222222222222</span>
</div>
</div>
解决方案
推荐阅读
- python - 指定范围内的输出元素
- react-native-draggable-flatlist - 如何实现两个可拖动的Flatlist
- javascript - ethereum web3js 如何导入“crypto-js”?
- sqlite - sqlite3 二进制数据类型
- python - 小鼠插补的运行时间估计?
- r - 有没有办法制作一个逻辑向量来查看向量的每个元素是否存在于另一个向量的所有元素中?
- aws-sdk - Javascript 中 AWS 开发工具包客户端生命周期的最佳实践
- android - android应用程序:单击菜单时操作栏重叠视图
- javascript - 迭代 Handlesbars.js 中的对象数组
- postgresql - 有没有办法阻止此错误“从“client_api_key”中选择 *,其中“api_key”= $1 限制 $2 - 连接意外终止”