<!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>上中下</title>
<style>
html *{
padding: 0;
margin: 0;
box-sizing: border-box;
}
html, body{
width: 100%;
height: 100%;
}
header{
position: absolute;
top: 0;
width: 100%;
height: 50px;
background-color: #ff5253;
}
main{
width: 100%;
min-height: 100%;
background-color: #999;
padding-top: 50px;
font-size: 30px;
color:#000;
}
main div{
width: 100%;
height: 400px;
}
footer{
width: 100%;
height: 80px;
background-color: blue;
margin-top: -80px;
}
</style>
</head>
<body>
<header>header頭部</header>
<main>
<div>1</div>
<div>1</div>
</main>
<footer>
footer 底部
</footer>
</body>
</html>
使用calc季蚂, vh實(shí)現(xiàn)
<!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>上中下</title>
<style>
html *{
padding: 0;
margin: 0;
box-sizing: border-box;
}
html, body{
width: 100%;
height: 100%;
}
header{
position: absolute;
top: 0;
width: 100%;
height: 50px;
background-color: #ff5253;
}
main{
width: 100%;
min-height: calc(100vh - 80px);
/* background-color: #999; */
padding-top: 50px;
font-size: 30px;
color:#000;
}
main div{
width: 100%;
height: 400px;
}
footer{
width: 100%;
height: 80px;
background-color: blue;
/* margin-top: -80px; */
}
</style>
</head>
<body>
<header>header頭部</header>
<main>
這是主體部分
<div></div>
</main>
<footer>
footer 底部(默認(rèn)置底,頁面高度超出一屏幕 footer展示在滾動最下面)
</footer>
</body>
</html>