stickey-footer实现footer固定页面底部

       先看看实现效果:http://getbootstrap.com/2.3.2/examples/sticky-footer.html 

        当一个网页比较简单,内容比较少使得网页不足浏览器高的时候,为了显示更合理,我们希望让 footer 部分显示在浏览器的底部。即让页面内容刚好满屏,这样视觉效果会比较好。

        我们页面内容布局是这样的:

       

  <body>  
    <div id="wrap">
      <div id="main">
      </div>
    </div>

    <div id="footer">
    </div>
  </body>

  

        下面描述下用stickey-footer的实现方案:

/*  
Sticky Footer Solution
by Steve Hatcher 
http://stever.ca
http://www.cssstickyfooter.com
*/

* {margin:0;padding:0;} 

/* must declare 0 margins on everything, also for main layout components use padding, not 
vertical margins (top and bottom) to add spacing, else those margins get added to total height 
and your footer gets pushed down a bit more, creating vertical scroll bars in the browser */

html, body {height: 100%;}

#wrap {min-height: 100%;}

#main {overflow:auto;
    padding-bottom: 180px;}  /* must be same height as the footer */

#footer {position: relative;
    margin-top: -180px; /* negative value of footer height */
    height: 180px;
    clear:both;} 

/*Opera Fix*/
body:before {/* thanks to Maleika (Kohoutec)*/
content:"";
height:100%;
float:left;
width:0;
margin-top:-32767px;/* thank you Erik J - negate effect of float*/
}



/* IMPORTANT

You also need to include this conditional style in the <head> of your HTML file to feed this style to IE 6 and lower and 8 and higher.

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

*/

 

posted @ 2014-04-28 11:46  地狱火之歌  阅读(263)  评论(0编辑  收藏  举报