1.flex方法
<!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>
<style>
body{
display: flex;
flex-flow: column;
min-height: 100vh;
overflow: auto;
}
.container{
flex:1;//占据剩余空间
}
.close{
height:100px;
background: red;
}
</style>
</head>
<body>
<div class="container">
<div class="main">
<p>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</p>
</div>
</div>
<div class="close" style="font-size: 30px;">
x
</div>
</body>
</html>
2.伪元素after
<!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>
<style>
*{
margin:0;
}
html,body{
height:100%;
}
.container{
min-height: 100%;
margin-bottom:-100px;//-100PX用来抵消after的100px
}
.container:after{
content:'';
display: block;
height:100px;//也可以设置1px撑开container的高度(如果要求不严格的话)
}
</style>
</head>
<body>
<div class="container">
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
<p>hhhhhhhhhhhhhhhhhhh</p>
</div>
<div class="close" style="font-size: 30px;height:100px;background: red;">
x
</div>
</body>
</html>