【发布时间】:2012-11-21 01:01:11
【问题描述】:
我有一个不占据整个屏幕的 HTML 页面。它只占用 HTML 内容的大小,并且页脚不在页面末尾(应该如此)
我该如何解决?
我只需要页脚位于页面末尾。
我的HTML结构如下:
<body>
<div id="app">
<!-- Header -->
<div id="header"></div>
<!-- Hero container -->
<div class="container">
<!-- Sub container -->
<div class="container"></div>
</div>
<!-- Footer -->
<div id='footer'></div>
</div>
</body>
我的 CSS 如下:
html {
height: 100%;
}
body {
color: hsl(0, 0%, 33%);
font-family: Helvetica, Arial, sans-serif;
font-size: 13px;
line-height: 1;
background: none repeat scroll 0 0 hsl(0, 0%, 98%);
margin: 0;
padding: 0;
height: 100%;
}
* {
outline: 0 none;
}
#app {
min-height: 100%;
margin:auto;
width: 100%;
}
div,span,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,a,big,cite,code,del,dfn,em,img,small,strike,strong,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tr,th,td,embed,menu,nav
{
border: 0 none;
font: inherit;
margin: 0;
padding: 0;
vertical-align: baseline;
}
.container {
margin: 0 auto;
position: relative;
width: 990px;
}
#footer {
margin: 100px 0 0;
}
谁能指导我。我是 CSS 新手。 :( 卡住了! :(
编辑
可能是因为我在 body 的一些 div 元素中有浮动?
编辑 2
奇怪的是,即使页面很长并且我向下滚动,在页脚之后还有一小条空白区域永远不会消失。 当我尝试使用 Firebug 选择空白区域时,它会将我显示为元素。
【问题讨论】:
-
您正在寻找的是一个粘性页脚:ryanfait.com/sticky-footer
-
如果您的内容超出窗口的高度,您的预期行为是什么?页脚会出现在视口底部还是页面底部?我问是因为您可以使用 position:fixed 或其他技术。
-
在stackoverflow.com/questions/13180981/… 上查看我的回答以获得粘性页脚
-
@MikeRobinson,如果内容超过窗口的高度,页脚应该出现在页面底部而不是视口。