布局左边自适应,右边固定宽度
flex 左边自适应,右边固定宽度
// html
<div class="demo">
<div class="left">
</div>
<div class="right">
</div>
</div>
// style
.demo {
border: 3px solid red;
display: flex;
align-items: stretch;
// 左右空白比为 0:1,所以右边会分配到剩余空白的所有空间
.left {
background: #F7E8B4;
// 宽度自动填充
width: auto;
// 有多余的项目空间,分配
flex-grow: 1;
height: 200px;
}
.right {
background: #B4D3F7;
// 设置宽度
width: 200px;
min-width: 200px;
max-width: 200px;
// 有多余的项目空间,不分配
flex-grow: 0;
}
}
项目中踩坑集锦



Last updated