<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>上下两个div上面值固定下面铺满高度</title>
<style type="text/css">
/*在body只有一个div的时候,可以通过这样的方式让div撑满整个屏幕。
1.给div设置定位。
复习一下——
css中position有五种属性:
static:默认值,没有定位
absolute:绝对定位,相对于父级元素进行定位
relative:相对定位
fixed:固定定位,相对于浏览器窗口进行定位
inherit:从父元素继承定位信息
除了默认值static和inherit之外,添加其他三种都可以实现窗口自适应。*/
/*方式1 :*/
/* *{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
}
.parentDiv{
width:100%;
height:100%;
display:flex;
flex-direction: column;
}
.childDiv1{
background-color: blanchedalmond;
width:100%;
height: 200px;
}
.childDiv2{
background-color: #0f8bcb;
width:100%;
flex:1;
}
*/
/*方式二2. 通过设置html,body的宽高来让div充满屏幕*/
* {
margin: 0;
padding: 0;
}
.parentDiv {
width: 100%;
height: 100%;
background: yellow;
position: absolute;
}
.parentDiv {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
.childDiv1 {
background-color: blanchedalmond;
width: 100%;
height: 200px;
}
.childDiv2 {
background-color: #0f8bcb;
width: 100%;
flex: 1;
}
</style>
</head>
<body>
<div class="parentDiv">
<div class="childDiv1">1111</div>
<div class="childDiv2">2222</div>
</div>
</body>
</html>
效果图: