首頁 > web前端 > html教學 > 内容较少时,页面的footer始终显示在底部,不是使用fixed。_html/css_WEB-ITnose

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

WBOY
發布: 2016-06-21 09:19:10
原創
1295 人瀏覽過

一、使用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).

* {

margin: 0;

}

html, body {

height: 100%;

}

.wrapper {

min-height: 100%;

height: auto !important;

height: 100%;

margin: 0 auto -4em;

}

.footer, .push {

height: 4em;

}

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.

    

        

    

    

        

            

Your website content here.

            

        

        

    

二、使用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");    }    //希望这段代码对你有用!
登入後複製


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板