背景
实现一个上下弹性盒,左右弹性盒,左右盒子中又有弹性盒的布局。
codepen代码
横向盒 弹性盒内容超出
<div class='top'><div class='left'></div><div class='right'>23534设防的稳定服我的文档5435</div></div>
.top{height:30px;background:red;display:flex;.left{width:1460px;}.right{flex:1;// 可以 建议方案width:0;// 也可以// overflow:hidden;}}
竖向盒 弹性盒内容超出
<div class='main-left'><div class='main-left-main'><div class='wrapper'><div class='demo'> erf </div></div></div><div class='main-left-top'></div></div>
目前增加一个可滚动绝地定位容器解决内容多导致的超出问题。(当然你可以常识用calc得出计算高度,或者再降级设置一个最大的高度)
.main-left{flex:1;background:yellow;display:flex;flex-direction:column;overflow:hidden;}.main-left-top{height:30px;}.main-left-main{flex:1;background:pink;overflow:hidden;height:0;position:relative;.wrapper{position:absolute;top:0;bottom:0;left:0;right:0;overflow:auto;}// 测试的demo元素.demo{height:700px;overflow:auto;}}
然后我测试了下简单的弹性盒的表现,就是只有垂直方向的弹性盒,不是弹性套弹性盒,这种设置overflow:auto即可。
<div class='m-container'><div class='m-main'><div style="height:400px"></div> </div><div class='m-top'>sdf </div></div>
.m-container{display:flex;width:100%;flex-direction:column;}.m-top{height:380px;}.m-main{flex:1;background:red;white-space:normal;word-break:break-all;// height:calc(100vh - 700px);overflow:auto;}
更多
属性生效顺序 :width|height > 内容大小 > flex空间
