【发布时间】:2013-05-30 13:32:46
【问题描述】:
我有两个页面,它们的区别仅在于 content-box div 标记中包含的内容。你可以在这里看到它们:
我在下面包含了 short 版本的 html/css 代码。我希望显示 short 版本,这样如果内容量没有填满整个页面,页脚仍然会粘在底部以及页眉和页脚之间的整个区域屏幕中间是白色对应content-box div。
我需要改变什么来完成这个?\
更新 1 我按照@smallworld 的建议创建了一个新页面。可以看到here。这有一个粘性页脚,但我希望外部“容器”框可以扩展页面的高度。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content=
"text/html; charset=us-ascii">
<style type="text/css">
#main {
width: 100%;
min-height: 100%;
height: 100%;
}
body {
width: 100%;
}
#header,#content { position:relative; right:0;left:0}
#header{
height:75px; top:0;
background: #4396CA;
}
#footer{
width: 100%;
position: relative;
height:50px;
bottom: 0;
left: 0;
background: #4396CA;
}
#content{
top:00px;
background: #F0F8FF;
min-height: 100%;
height: 100%;
}
#content-box {
width: 950px;
margin: 0 auto;
background-color: #FFFFFF;
text-align: left;
border-right: 1px solid #B0B0B0;
border-left: 1px solid #B0B0B0;
padding-bottom: 20px;
padding-top: 20px;
min-height: 100%;
height: 100%;
}
</style>
<title>EmbeddedAnalytics - Test Page</title>
</head>
<body>
<div id="main">
<div id="header">this is header</div>
<div id="content">
<div id="content-box">
<b>Content does not take up all of box. But still want footer to "stick" to bottom</b><br>
line1<br>
line2<br>
line3<br>
Last Line<br></div>
</div>
<div id="footer">footer</div>
</div>
</body>
</html>
【问题讨论】:
-
是的 - 我搜索了“粘性页脚”,但显然没有正确地做某事。
-
这是我基于的一个页面:pud.ca/misc/testcase/fullheight.html 我认为让这更复杂的是“内容”中的“内容框”。我见过的大多数粘性示例都是基本的,因为只有三个块:页眉、内容、页脚。
-
您的代码与 fullheight.html 示例完全不同。在他们的示例中,body 和 html 有
height: 100%,页脚是绝对定位的,等等。尝试按照这些示例之一进行操作,如果遇到问题,请寻求帮助。 -
是的 - 我从 fullheight.html 示例开始。但我不得不分叉它,因为我的页面有嵌套容器。所以它是不同的。请参阅更新 1