* {
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:子>