本文介紹了詳解HTML5將footer置于頁面最底部的方法(CSS+JS),分享給大家,具體如下:
JavaScript:
<script type="text/javascript"> $(function(){ function footerPosition(){ $("footer").removeClass("fixed-bottom"); //網頁正文全文高度 var contentHeight = document.body.scrollHeight, //可視窗口高度,不包括瀏覽器頂部工具欄 winHeight = window.innerHeight; if(!(contentHeight > winHeight)){ //當網頁正文高度小于可視窗口高度時,為footer添加類fixed-bottom $("footer").addClass("fixed-bottom"); } else { $("footer").removeClass("fixed-bottom"); } } footerPosition(); $(window).resize(footerPosition); });</script>
CSS:
.fixed-bottom { position: fixed; bottom: 0; width:100%;}
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答