【发布时间】:2022-02-02 22:05:12
【问题描述】:
我有一个弹性盒子,它会根据里面的内容逐列增长;盒子的宽度应该适合内容。我必须将此框放在绝对定位在页面上的父容器中。
如果这样做,父容器不会采用子容器的动态宽度,而是坚持其初始宽度并且子容器会溢出。
可用代码:https://jsfiddle.net/visu310p/q8hsk42L/8/
.parent {
color: white;
background: blue;
margin: auto;
padding: 1em;
position: absolute;
left: 10px;
top: 100px;
}
.child {
background-color: green;
display: flex;
height: 100px;
flex-direction: column;
flex-wrap: wrap;
margin: 0;
}
【问题讨论】:
-
这里的child会有自动宽度,会随着flex的内容而增长,所以我真的不知道它会拉伸多少。