【发布时间】:2014-02-13 09:42:24
【问题描述】:
我需要有一个固定高度的页眉、一个固定高度的页脚和一个 100% 高度的 div 夹在它们之间(它包含一个完整的页面背景图像)。我正在使用粘性页脚,因为这是一个模板,也将用于具有可能溢出的常规内容的页面(没有背景图像)。这适用于常规页面,但在需要 100% 高度容器的页面上,它会失败。我无法将 100% 的高度 div 扩展到 100%。任何帮助将不胜感激。
这是显示我在使用 100% 高度 div 时遇到的问题的测试页面:http://www.dunnandtigheinteriors.com/new/wp-content/themes/dunntighe/testhome.html
html, body {
margin: 0;
padding: 0;
height: 100%;
}
body {
font-family: Georgia, Times, "Times New Roman", serif;
background: #EFEFEF;
font-size: 14px;
}
#wrapper {
min-height: 100%;
/* height: 100%;
position: relative; Required to absolutely position the footer
text-align: center;*/
}
#headerHolder {
width: 100%;
background: #FFFFFF;
height: 50px;
}
#bkgHolder {
width: 100%;
height: calc(100% - 100px);
background: #DEDFE1;
padding-bottom: 25px;
background-image: url('images/DunnTigheWhiteOverlay.png');
background-repeat: no-repeat;
background-position: center;
background-size: auto 100%;
overflow:auto;
padding-bottom: 25px; /* must be same height as the footer */
}
#footerHolder {
text-align: center;
font-size: 10px;
height: 25px;
color: #888888;
background-color: #0074a2;
/* position: absolute;*/
/* bottom: 0; Sit it on the bottom
left: 0;*/
width: 100%; /* As wide as it's allowed */
position: relative;
margin-top: -25px;
clear:both;
}
#footerHolder p {
padding: 5px 0 0 0;
margin: 0;
}
#pageText {
overflow:auto;
padding-bottom: 25px; /* must be same height as the footer */
}
.pageContent {
text-align: left;
width: 680px;
margin: 0 auto;
padding-bottom: 15px;
}
和html
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="test.css" media="screen" />
</head>
<body>
<div id='wrapper'>
<div id="headerHolder">
</div>
<div id="bkgHolder">
<div id='content'>
some content here
</div>
</div>
</div>
<div id="footerHolder">
<p>All Content and Images, Copyright © Dunn & Tighe Interiors</p>
</div>
</body> </html>
【问题讨论】:
-
介意我重写你的模板吗?我有一个更简单的解决方案。
-
如果我将 height: 100% 添加到包装器上,它会解决 100% 高度页面的问题,但随后会导致溢出的页面中断(粘性页脚不会移动到底部)。
-
我明白了。我正在为完整的内容和缺乏内容制作一个真正快速的模板:-)。请稍等。
-
抱歉,让您的 BG 图像工作了这么久。
标签: css height sticky-footer