1、盒子内均分
<!DOCTYPE html><html><head><meta charset="utf-8"><style>//如果在大div内不添加弹性布局,三个div垂直排列(弹性布局默认横向排列).flex-container {display: -webkit-flex;display: flex;width: 400px;height: 250px;background-color: lightgrey;}.flex-item {background-color: cornflowerblue;height: 100%;margin: 10px;//用百分比width: 33.33%;//占比flex-grow,控制占比是横向占比还是纵向占比,跟弹性布局的排列方式有关//每个小div占比为1,盒子均分为三分每份为1flex-grow:1;}</style></head><body><div class="flex-container"><div class="flex-item">flex item 1</div><div class="flex-item">flex item 2</div><div class="flex-item">flex item 3</div></div></body></html>
2、三个板块,左右固定,中间自适应
上下高度固定,中间自适应相同的道理
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
//左右宽度固定,中间小divflex-grow:1;占满剩余的
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
}
.flex-item1 {
background-color: cornflowerblue;
height: 100%;
margin: 10px;
width:200px;
}
.flex-item2 {
background-color: cornflowerblue;
height: 100%;
margin: 10px;
flex-grow:1;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-item1">flex item 1</div>
<div class="flex-item2">flex item 2</div>
<div class="flex-item1">flex item 3</div>
</div>
</body>
</html>
