在內容不超過一屏的情況下,當瀏覽器窗口變小那行頁腳文字會跟著向上浮動但還是保持在底部。
當內容多出一屏時,他顯示在網頁的最下邊,而不是窗口的最下邊;測試了一下,還可以,在ie6、ie7、ff等都沒有問題!窗口縮小時也沒有問題!
首先是js腳本:
function test(){
var infoheight = document.getelementbyid("info").scrollheight;
var bottomheight = document.getelementbyid("bottom").scrollheight;
var allheight = document.documentelement.clientheight;
var bottom = document.getelementbyid("bottom");
if((infoheight + bottomheight) < allheight){
bottom.style.position = "absolute";
bottom.style.bottom = "0";
}else{
bottom.style.position = "";
bottom.style.bottom = "";
}
settimeout(function(){test();},10);
}
test();
查看運行效果:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>css實例:讓頁腳保持在未滿屏頁面的底部</title>
<style>
*{ margin:0; padding:0}
#info{background:#33ccff}
#bottom{background:#ffcc00;width:100%;}
</style>
</head>
<body>
<div id="info">
2<br />2<br />2<br />2<br />2<br /><br />2<br />2<br />2<br />2<br />2<br /><br />2<br />20000</div>
<div id="bottom">bottom</div>
<script language="javascript" type="text/javascript">
function test(){
var infoheight = document.getelementbyid("info").scrollheight;
var bottomheight = document.getelementbyid("bottom").scrollheight;
var allheight = document.documentelement.clientheight;
var bottom = document.getelementbyid("bottom");
if((infoheight + bottomheight) < allheight){
bottom.style.position = "absolute";
bottom.style.bottom = "0";
}else{
bottom.style.position = "";
bottom.style.bottom = "";
}
settimeout(function(){test();},10);
}
test();
</script>
</body>
</html>
新聞熱點
疑難解答