参考自:CSS to make HTML page footer stay at bottom of the page with a minimum height
示例1:
代码:
<html>
<head>
<style>
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}
</style>
</head>
<body>
<div id="container">
<div id="header"></div>
<div id="body">
<!--<h1 style="margin:100px 0"> hi </h1>
<h1 style="margin:100px 0"> world </h1>-->
</div>
<div id="footer"></div>
</div>
</body>
</html>
#6cf
类似绿色。
效果:
示例2:
把示例1中body里h1的注释去掉。
效果为: