【发布时间】:2015-03-11 10:58:39
【问题描述】:
我目前正在开发一个要求页脚位于底部的网络应用程序。我能够将页脚移到底部,但在我的屏幕上,尽管内容没有占据整个页面,但我必须向下滚动才能看到页脚。
我有以下用于粘性页脚的 CSS 代码:
html, body {
height: 100%;
width: 100%;
}
#container {
overflow: none;
width: 80%;
min-height: 100%;
margin: 0 auto -2em; /* Height of footer */
}
.push {
height: 2em;
}
.primary-footer {
width: 100%;
}
.primary-footer .copyright {
height: 2em;
background: red;
color: #fff;
padding-left: 20%;
padding-top: 0.5%;
clear: both;
}
项目布局见:https://jsfiddle.net/7m6Lqmww/
基于 jsfiddle,它在较小的屏幕上似乎可以正常工作,但在较大的屏幕上,会出现一个垂直条。
【问题讨论】:
-
你可以试试这个技巧,我觉得它更聪明-stackoverflow.com/a/28920634/483779
-
等一下,您是否想让页脚始终位于屏幕底部?就像即使您向下滚动页脚也会“卡在”显示屏底部一样?像这样cssplay.co.uk/layouts/bodyfix.html 滚动时保留的东西会粘在底部吗?
-
不,我只需要它在不需要时不显示滚动条,我认为@sdcr 解决方案对我的情况很有效。
标签: html css web-applications