内容较少时,页面的footer始终显示在底部,不是使用fixed。

一、使用css,参考国外的一个解决方法:

http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

How to use the CSS Sticky Footer on your website

Add the following lines of CSS to your stylesheet. The negative value for the margin in .wrapper is the same number as the height of .footer and .push. The negative margin should always equal to the full height of the footer (including any padding or borders you may add).

  1. * {

  2. margin: 0;

  3. }

  4. html, body {

  5. height: 100%;

  6. }

  7. .wrapper {

  8. min-height: 100%;

  9. height: auto !important;

  10. height: 100%;

  11. margin: 0 auto -4em;

  12. }

  13. .footer, .push {

  14. height: 4em;

  15. }

Follow this HTML structure. No content can be outside of the .wrapper and .footer div tags unless it is absolutely positioned with CSS. There should also be no content inside the .push div as it is a hidden element that "pushes" down the footer so it doesn't overlap anything.

  1. <html>

  2.     <head>

  3.         <link rel="stylesheet" href="layout.css" ... />

  4.     </head>

  5.     <body>

  6.         <div class="wrapper">

  7.             <p>Your website content here.</p>

  8.             <div class="push"></div>

  9.         </div>

  10.         <div class="footer">

  11.             <p>Copyright (c) 2008</p>

  12.         </div>

  13.     </body>

  14. </html>

二、使用js,参考这个:(本人未验证过,看代码应该可行)

http://jingyan.baidu.com/article/2fb0ba4054805900f2ec5f9d.html

  //footer吸底效果
    var _ch = $("#content").height();//这个就是你中间内容div的高度
    var _wh = $(window).height();//整个窗口的高度
    //console.log("window's height",_wh,"content's height",_ch,"_wh - _ch:",_wh - _ch);
    if(_wh - _ch > 192){
        $("#content").css("min-height",(_wh-192)+"px");
    }
    //希望这段代码对你有用!


转载于:https://my.oschina.net/kavensu/blog/362001

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值