Html 如何将页脚定位在页面底部或内容下方

Html 如何将页脚定位在页面底部或内容下方,html,css,position,footer,Html,Css,Position,Footer,我希望我的页脚一直在页面底部,因为我的页面没有那么长 但是,当页面比屏幕长时,它需要像一个合适的页脚一样位于内容下方,而不是卡在屏幕底部。如果页脚的高度固定,最简单且只有CSS的解决方案是: CSS html { position: relative; min-height: 100%; } body { /* height of the footer */ margin: 0 0 120px 0; } footer { position: absol

我希望我的页脚一直在页面底部,因为我的页面没有那么长


但是,当页面比屏幕长时,它需要像一个合适的页脚一样位于内容下方,而不是卡在屏幕底部。

如果页脚的高度固定,最简单且只有CSS的解决方案是:

CSS

html {
    position: relative;
    min-height: 100%;
}

body {
    /* height of the footer */
    margin: 0 0 120px 0;
}

footer {
    position: absolute;
    bottom: 0;
    height: 120px;
}
演示

    • 这可能会有所帮助


      谢谢,这正是我需要的。