【发布时间】:2013-08-30 10:14:04
【问题描述】:
我想将页脚放在页面底部,它也有一个固定的页眉...
不适用于
position: fixed- 我不希望它保留在屏幕上,它应该只是在页面的末尾并且在滚动时表现正常。不在可见屏幕底部 - 在页面底部,即;在所有其他内容之后。
下面的图表可以更好地解释:
代码如下:
- 我准备了一个演示:JSFiddle
- 或见下文
<div id="header">Header</div>
<div id="content">
<p>Some content...</p>
</div>
<div id="footer">Footer</div>
body{
/* Just to enable scrolling in JSFiddle */
height: 1000px;
}
#header{
width: 100%;
height: 100px;
position: fixed;
top: 0px;
z-index: 1;
}
#content{
width: 100%;
position: absolute;
top: 100px; /*Height of header*/
z-index: 0;
}
#footer{
width: 100%;
height: 100px;
position: absolute;
bottom: 0px;
}
/*For demo only*/
#header, #footer{
border: 3px dashed #333333;
background: #FFFFFF;
}
#content{
background: #CCCCCC;
height: 200px;
}
【问题讨论】:
-
我的代码格式似乎有问题。如果有人可以编辑,我将不胜感激。
-
你在用IE吗?当我在 IE 中查看时,格式确实搞砸了!
-
content需要有absolute的位置吗? -
为什么不为您的内容和页脚使用一些相对位置?我的意思是你使用 margin-top : 100px;对于内容,您只需将页脚放在它之后。
-
@HashemQolami,我想是的。因为header是固定位置的,所以保证内容是可见的。
标签: html css sticky-footer