HTML中footer固定在页面底部的若干种方法

1 <div class="header"><div class="main"></div></div>
2 <div class="container"><div class="main"></div></div>
3 <div class="footer"><div class="main"></div></div>

如果主体内容过短不足以支撑浏览器时,footer会上移,非常影响页面,算是一个大bug了,搜过很多种方法现整理一下footer固定在第的若干种方法,供以后参考。(欢迎大家积极补充。)

以上布局为给个人写页面常用。

注:.main{

width:1050px;

margin:0 auto;

height:auto;

}

1、这是刚刚使用过的css,可以达到效果,只是不论浏览器的大小如何footer均会在底,主体内容则以滚动条形式显示。

缺点:小分辨率下达不到好的视觉体验,主体以滚动条显示,不合格

.footer{

position:fixed;

bottom:0;

left:0;

}

2、

 目前用的是这种,经试验可以满足需要

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title>footer需要固定在底部</title>
 6         <style type="text/css">
 7             html,body{font-size: 14px;font-family: "微软雅黑";text-align: center;width: 100%;height: 100%;min-height: 100%;border:0;line-height: none;}
 8             p{border: 0;margin: 0;padding: 0;line-height: none;}
 9             body{padding:0px; margin:0px ;}
10             .container{position:relative;height: auto;min-height: 100%;margin: 0}
11             .container .header{height: 100px;background: #0000FF;}
12             .container .push{padding-bottom: 100px;}
13             .footer{position:relative;height: 100px;margin-top:-100px;background: #0000FF;}
14             
15         </style>
16     </head>
17     <body>
18         <div class="container">
19             <div class="header">
20                 <p>头部文本</p>
21             </div>
22             <div class="content">
23                 <p>主体内容</p>
24             </div>
25             <div class="push"></div><!--push在此为footer占位,高度和footer的一样-->
26         </div>
27         <div class="footer">
28             <p>底部文本</p>
29         </div>
30         
31     </body>
32 </html>

 

posted on 2015-10-21 10:30  小苏打00  阅读(8079)  评论(6编辑  收藏  举报