用户登陆|注册论坛|联系我们|网站地图
您的位置:主页>网页设计>CSS教程>正文
站内搜索:
CSS实例:让页脚保持在未满屏页面的底部
53vi.com 日期:2008-03-20 浏览: 来源:互联网 【

  在内容不超过一屏的情况下,当浏览器窗口变小那行页脚文字会跟着向上浮动但还是保持在底部。

  当内容多出一屏时,他显示在网页的最下边,而不是窗口的最下边;测试了一下,还可以,在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>


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
资讯先锋网·资讯前沿-技术先锋
关于我们 | 广告服务 | 免责声明 | 版权隐私 | 友情链接 | 欢迎投稿 | 网站地图 | 联系我们
CopyRight © 2007-2008 53vi.com All Rights Reserved
通用搜索:百度  谷歌  Yahoo!  Live  搜狗
资讯先锋网版权所有