CSS布局:让页底内容永远固定在底部

我们在设计一些页面内容甚少的网页时(典型应用就是登陆页面),由于显示器的分辨率大,在正常情况下,假如页面内容高度小于浏览器高度时,页面底部以下会留下很大的空间,如:http://www.helloweba.com/demo/cssfooter/demo1.html

不管浏览器的高度怎么变化,我们要想让页底内容始终固定在底部,最终效果如:http://www.helloweba.com/demo/cssfooter/demo2.html

<!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>无标题文档</title>
<style type=”text/css”>
* {margin:0;padding:0;}
html, body {height: 100%;}
#wrap {min-height: 100%;}
#main {overflow:auto;background:#f7f7f7;
padding-bottom: 60px;}  /* 必须使用和footer相同的高度 */
#footer {position: relative;
margin-top: -60px;
height: 60px;
clear:both;
background:#369}

/*Opera Fix*/
body:before {
content:”";
height:100%;
float:left;
width:0;
margin-top:-32767px;
}

</style>
<!–[if !IE 7]>
<style type=”text/css”>
#wrap {display:table;height:100%}
</style>
<![endif]–>
</head>

<body>
<div id=”wrap”>
<div id=”main”>
主体
</div>

</div>

<div id=”footer”>
这里是页底footer内容
</div>

</body>
</html>

声明: 本文采用 BY-NC-SA 协议进行授权 | CrossYou
转载请注明转自《CSS布局:让页底内容永远固定在底部

这篇文章目前没有评论

Leave a Reply
你必须先logged in才能发送评论