* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
height: 142px; /* .push must be the same height as .footer */
}
/*
Sticky Footer by Ryan Fait
http://ryanfait.com/
*/
* {
margin: 0;
}
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */
}
footer, .push {
height: 142px; /* .push must be the same height as .footer */
}
Ryan Fait 的粘性页脚是一个简单的解决方案,我过去曾多次使用过。
基本 HTML:
CSS:
将其翻译为类似于您已经得到的结果,大致如下:
HTML:
CSS:
只是不要忘记更新包装边距上的负数以匹配页脚和推送 div 的高度。祝你好运!
Ryan Fait 的粘性页脚 是非常好,但是我发现它缺乏基本结构*。
Flexbox 版本
如果您足够幸运,可以使用 Flexbox 而无需支持旧版浏览器,那么粘性页脚就会变得非常简单,并且支持动态调整大小的页脚。
使用 Flexbox 让页脚粘在底部的技巧是让同一容器中的其他元素垂直弯曲。它所需要的只是一个带有
display: flex
的全高包装元素和至少一个flex
值大于0
的同级元素: p> CSS:子>