当我在没有内容的情况下使用position: relative
时,页脚上移;当有很多内容时使用position: absolute
,页脚下移;当使用position: fixed
时,页脚一直存在。
是否有简单的方法使页脚独立于内容出现在页面底部,并随着内容的增减而伸缩?
当页面存在大量内容时,我们可以在第一页看到页脚;而当内容很少时,我们会在底部看到页脚。
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html,body {
padding: 0;
margin: 0;
}
header {
position:fixed;
top:0;
width:100%;
height:40px;
background-color:#333;
padding:20px;
}
footer {
background-color: #333;
width: 100%;
bottom: 0;
position: relative;
}
#main{
padding-top:100px;
text-align:center;
}
</style>
</head>
<body>
<header>
header
</header>
<div id="main">
main
</div>
<footer>
footer
</footer>
</body>
</html>