【发布时间】:2012-11-07 12:25:36
【问题描述】:
我正在尝试创建一个底部固定有页脚的模板。我已经成功地尝试了不同的方法,但现在我发现无法将二级内容 div 扩展到 100% 高度。我尝试过 Ryan Fait、David Walsh 并搜索其他方法。我知道这是一个常见问题,但在 stackoverflow 中我还没有看到解决方案。
您可以在此处查看示例:http://jsfiddle.net/charlyta/hyfUe/
* {
margin: 0;
padding: 0;
}
body, html {
height: 100%;
}
#container {
background: #f00; /* styling only */
width: 100%;
margin: 0 auto;
position: relative;
height: auto !important;
min-height: 100%;
height: 100%;
}
#content {
padding-bottom: 100px;
width: 980px;
background-color: #FFF;
margin: 0 auto;
min-height: 100%;
margin-top: -20px;
-webkit-box-shadow: 0px 1px 3px rgba(27, 57, 50, 0.44);
-moz-box-shadow: 0px 1px 3px rgba(27, 57, 50, 0.44);
box-shadow: 0px 1px 3px rgba(27, 57, 50, 0.44);
-moz-border-radius: 5px;
border-radius: 5px;
position: relative;
max-height:100%;
height:auto !important;
height: 100%;
overflow: hidden;
}
#footer {
position: absolute;
left: 0;
bottom: 0;
height: 100px;
width: 100%;
background: #0f0;
}
#header {
height: 100px;
width: 100%;
background: #0f0;
}
</style>
<div id="container">
<div id="header">
header
</div>
<div id="content">
Your content goes here
</div>
<div id="footer">
Footer here
</div>
</div>
</body>
【问题讨论】:
-
您是要创建列还是行?
-
不,我不是要创建列或行,只是一个 100% 高度的 div:内容
-
您希望 div 自动调整到内容的高度?对吗?
-
不确定这是否是您所追求的,但我会尝试一下-通过将透明背景应用于#content并将您想在#content上看到的背景设置为#容器
标签: css