javascript - 求助!!! Html Css Footer的設定

來源:互聯網
上載者:User

要求

  • 1.網頁內容少時,footer再瀏覽器的底部,如

  • 2.網頁內容多時,瀏覽內容時(未瀏覽到底部)footer不可見,如

  • 3.網頁內容多時,瀏覽內容時(瀏覽底部)footer可見,如

回複內容:

要求

  • 1.網頁內容少時,footer再瀏覽器的底部,如

  • 2.網頁內容多時,瀏覽內容時(未瀏覽到底部)footer不可見,如

  • 3.網頁內容多時,瀏覽內容時(瀏覽底部)footer可見,如

請搜尋sticky footer 有很多css就能做掉的方式 在能夠只顧支援flexbox的情況 我是用這個超清爽的方式 連結

將footer固定在頁面底部的實現方法

同求,之前採用 JS 動態計算,踩過不少坑。後來直接改為中間 content 設了個最小高度

footer: function() {        var footerHeight = 0,            footerTop = 0,            $footer = $(".footer");        positionFooter();        //定義positionFooter function        function positionFooter() {            //取到div#footer高度            footerHeight = $footer.height();            //div#footer離螢幕頂部的距離            footerTop = ($(window).scrollTop() + $(window).height() - footerHeight) + "px";            /* DEBUGGING STUFF                console.log("Document height: ", $(document.body).height());                console.log("Window height: ", $(window).height());                console.log("Window scroll: ", $(window).scrollTop());                console.log("Footer height: ", footerHeight);                console.log("Footer top: ", footerTop);                console.log("-----------")            */            //如果頁面內容高度小於螢幕高度,div#footer將絕對位置到螢幕底部,否則div#footer保留它的正常靜態定位            if (($(document.body).height() + footerHeight) < $(window).height()) {                $footer.css({                    position: "absolute",                    top: footerTop,                });            } else {                $footer.css({                    position: "static"                });            }        }

bootsrap官網下面有一個外掛程式 好像是handroom(具體忘記了)用於固定header的,footer應該也可以

謝謝大家,問題解決了,方法有好多
但是我在html中用的margin太多了,導致頁面無法完美100%顯示⊙﹏⊙b汗
最後用padding加上sticky footer的方法解決了

參考1
參考2
參考3

JS根據document的scrollTop與document.height-window.height的差,改footer的position:是relative還是fixed;~

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.