需求:
1)上下兩個盒子固定定位,中間的盒子自適應(yīng)高度。撐大剩余盒子高度。

Snipaste_2018-06-20_16-07-12.png
注意:
1)中間的盒子只能使用padding讓出位置,并且要增加box-sizing屬性。
2)marging不能達到該效果。
個人分析:
不能使用maging,因為margin先讓出位置,但讓出的位置還是屬性剩余高度,仍然 作為自己的高度。于是就溢出來。完整代碼如下:
<!--
需求:
1)上下兩個盒子固定定位,中間的盒子自適應(yīng)高度。撐大剩余盒子高度。
注意:
1)中間的盒子只能使用padding讓出位置,并且要增加box-sizing屬性。
2)marging不能達到該效果。
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<style>
html,body{
height: 100%;
}
.box{
width: 500px;
height: 100%;
background-color: #ccc;
}
.box1{
position: fixed;
top:0px;
left:0px;
width: 100%;
height: 100px;
background-color: red;
}
.box2{
height: 100%;
background-color: yellow;
/* 不能使用maging,因為margin先讓出位置,但讓出的位置還是屬性剩余高度,仍然作為自己的高度。
于是就溢出來。
*/
padding-top:100px;
padding-bottom:100px;
box-sizing: border-box;
}
.box3{
position: fixed;
bottom:0px;
left:0px;
width: 100%;
height: 100px;
background-color: green;
}
</style>
<div class="box">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</div>
</body>
</html>