简单来讲就是2边固定宽高,中间自适应
<div class="search">
<div class="left">左边</div>
<div class="center">中间的内容</div>
<div class="right">右边</div>
</div>
设置好DIV后 给父元素 .search添加属性display:flex;
.left盒子 和.right盒子设置固定宽高
.center设置属性 flex: 1;(伸缩比,占父元素盒子剩余的全部宽度)
经常用在移动端页面顶部导航,实际效果:
中间的内容宽度会根据浏览器宽度自适应
样式代码
.search {
width: 100%;
height: 50px;
background-color: pink;
/* 弹性容器 */
display: flex;
}
.search .left {
width: 50px;
height: 50px;
background-color: aqua;
}
.search .center {
flex: 1;
background-color: red;
}
.search .right {
width: 50px;
height: 50px;
background-color: aqua;
}