Sticky Footer (讓頁尾永遠停靠在頁面底部,而不是根據絕對位置),stickyfooter
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Author" content="胡超">
<title>super胡</title>
<style>
* {
margin:0;
padding:0;
}
html,body, #wrap
{
height: 100%;
}
body > #wrap
{
height: auto;
min-height: 100%;
}
#main
{
padding-bottom: 150px;
} /* must be same height as the footer */
#footer {
position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear:both;
border-color:1px solid red;
background:red;
}
/* CLEAR FIX*/
.clearfix:after
{content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix {display: inline-block;
}
/* Hides from IE-mac */
.clearfix { height: 1%;/*zoom:1*/
}
</style>
</head>
<body>
<div id="wrap">
<div id="main" class="clearfix">
</div>
</div>
<div id="footer"> sagsdhgdf
</div>
</body>
</html>
你會發現,頁尾的高度在這裡被重複使用了三次,這是至關重要的,而且三個高度必須使用同樣的值。wrap <div>的height屬性把自己展開至視窗全部高度的尺寸,負的margin會把footer提高到main <div>的padding的位置上去,因為main已經在wrap的裡面,所以main的padding已經是wrap 100%高度的一部分。 這樣,footer就留在頁面的底部了。
現在還不算完成,我們還需要去clearfix main <div>。
.clearfix:after {content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;}
.clearfix {display: inline-block;}
/* Hides from IE-mac \*/
* html .clearfix { height: 1%;}