【发布时间】:2017-10-03 19:52:10
【问题描述】:
我正在尝试将页脚放在页面底部,但不粘。当没有足够的内容覆盖屏幕高度时,我会遇到问题,然后页脚不在底部。我试图在 CSS 中这样设置它:
body {
position: relative;
margin: 0;
padding-bottom: 8rem;
min-height: 100%;
overflow-x: hidden;
}
footer {
position: absolute;
display: flex;
align-items: center;
height: 4rem;
right: 0;
bottom: 0;
left: 0;
background-color: $gray;
}
只有当有足够的内容时,此页脚才会出现在页面底部。但是,当没有足够的内容时,它就在底部之上。这是示例:
Here 是小提琴。
当我添加到 css 文件时,就像答案中建议的那样:
html, body {
height: 100%;
}
【问题讨论】:
-
请张贴html代码。如果你能创造一个小提琴,那将是最好的。