【发布时间】:2012-12-15 19:07:04
【问题描述】:
对于带有long content 的页面,我的网站看起来不错,但在带有short content 的页面上,页脚向上移动(编辑:链接现在显示一个正常工作的粘性页脚)。我已经尝试了多种解决方案,但我无法让它们中的任何一个起作用(在这里不起作用是页脚不粘,或者它出现在页面中间)。我试过this solution 和this one(我已经删除了这两种解决方案,所以我可以重新开始)。例如,如果您进入 chrome 开发人员工具或 firebug 并将height:100% 添加到#wrapper div(这实际上是使其工作的第一步),高度超过 100%,并且页脚不在底部。
基本的div结构如下:
<div id="wrapper">
<div id="container">
<div id="content">
<div class="post"></div> <!-- floats left -->
<div id="sidebar></div> <!-- floats right -->
<div style="clear:both"></div> <!-- clear hack -->
</div>
</div>
</div>
<div id="footer"></div>
以下是相关 div 的 CSS:
html {
height: 100%;
}
body {
min-width:900px;
height: 100%;
}
#container {
height: 100%;
padding: 20px;
background: #f4f4f4;
}
#content {
-moz-border-radius: 11px;
-webkit-border-radius: 11px;
border-radius: 11px;
margin: auto;
width: 80%;
max-width: 1000px;
min-width:800px;
padding: 10px;
background: white;
-moz-box-shadow: 0px 2px 6px 3px #C0C0C0;
-webkit-box-shadow: 0px 2px 6px 3px #C0C0C0;
box-shadow: 0px 2px 6px 3px #C0C0C0;
}
#footer {
padding: 10px;
text-align: center;
box-sizing: border-box;
background: #101010;
height: 14em;
color: white;
}
/* These two are probably less important */
#sidebar {
float: right;
height: 100%;
margin: 15px 25px;
-moz-border-radius: 11px;
-webkit-border-radius: 11px;
border-radius: 11px;
/*IE 7 AND 8 DO NOT SUPPORT BORDER RADIUS*/
-moz-box-shadow: 0px 0px 7px #000000;
-webkit-box-shadow: 0px 0px 7px #000000;
box-shadow: 0px 0px 7px #000000;
/*IE 7 AND 8 DO NOT SUPPORT BLUR PROPERTY OF SHADOWS*/
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr = '#ffffff', endColorstr = '#dcedeb');
/*INNER ELEMENTS MUST NOT BREAK THIS ELEMENTS BOUNDARIES*/
/*Element must have a height (not auto)*/
/*All filters must be placed together*/
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr = '#ffffff', endColorstr = '#dcedeb')";
/*Element must have a height (not auto)*/
/*All filters must be placed together*/
background-image: -moz-linear-gradient(top, #ffffff, #dcedeb);
background-image: -ms-linear-gradient(top, #ffffff, #dcedeb);
background-image: -o-linear-gradient(top, #ffffff, #dcedeb);
background-image: -webkit-gradient(linear, center top, center bottom, from(#ffffff), to(#dcedeb));
background-image: -webkit-linear-gradient(top, #ffffff, #dcedeb);
background-image: linear-gradient(top, #ffffff, #dcedeb);
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
/*Use "background-clip: padding-box" when using rounded corners to avoid the gradient bleeding through the corners*/
/*--IE9 WILL PLACE THE FILTER ON TOP OF THE ROUNDED CORNERS--*/
}
.post {
width: 100%;
float: left;
height: 100%;
}
任何人都可以使用 firebug 或 CDT 之类的东西来弄清楚为什么 100% 的高度不起作用以及如何获得粘性页脚吗?
编辑:
按照@ajkochanowicz 的描述实施 Ryan Fait 的解决方案后,页面如下所示:
您可以看到灰色背景(即#container div 的背景)没有延伸到#wrapper div 的底部,即使两者都有height: 100%。
【问题讨论】:
-
与其让我们浏览您的网站,您也可以发布您的 CSS 吗?没有它很难解决这个问题。
-
@ajkochanowicz 好的,等一下,我会发布我发布的 div 的 CSS。
-
(响应您的更新)这是因为包装器正在拉伸。不是容器。将包装器的背景设置为灰色而不是容器。
-
@ajkochanowicz 你能澄清一下吗?如何让容器填充包装器(至少到页脚)?
-
如果您只想让灰色一直向下,则不需要它。完全按照你之前的做法,但将灰色背景颜色放在#wrapper 上,而不是#container 上。
标签: html css height sticky-footer