javascript - 求助!!! Html Css Footer的设置
Jun 06, 2016 pm 08:16 PM
要求
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;~

Article chaud

Outils chauds Tags

Article chaud

Tags d'article chaud

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Guide d'installation et de mise à niveau de PHP 8.4 pour Ubuntu et Debian

Comment configurer Visual Studio Code (VS Code) pour le développement PHP
