如何使 Flex 中的父容器和其他子容器成长为最长的子容器之一

  • 本文关键字:成长 Flex 何使 其他 css flexbox
  • 更新时间 :
  • 英文 :


每当蓝色div内部的东西增长时,我需要容器和绿色div增长到与蓝色相同的大小。

.container {
background: grey;
height: 200px;
flex-direction: column;
padding: 10px;
display: flex;
}
.normal {
background: green;
}
.wide {
width: 2500px;
background: blue;
flex: 1 0 auto;
}
<div class="container">
<div class="normal">Normal</div>
<div class="wide">Wide</div>
</div>

代码笔

改为考虑inline-flex

.container {
background: grey;
height: 200px;
flex-direction: column;
padding: 10px;
display: inline-flex;
min-width:100%; /*to make sure it behave like flex if the content is small*/
box-sizing:border-box;
}
.normal {
background: green;
}
.wide {
width: 2500px;
background: blue;
flex: 1 0 auto;
}
<div class="container">
<div class="normal">Normal</div>
<div class="wide">Wide</div>
</div>

相关:为什么这里的外部

没有完全包围内部

最新更新