【发布时间】:2011-03-12 07:07:15
【问题描述】:
我正在尝试创建一个带有页眉和页脚(两者都有固定高度)的布局以及它们之间的 content-div 填充剩余空间。在 content-div 中,我希望 div 的高度基于百分比值(以 content-div 的 heihgt 作为父级)。我不知道该怎么做?
【问题讨论】:
我正在尝试创建一个带有页眉和页脚(两者都有固定高度)的布局以及它们之间的 content-div 填充剩余空间。在 content-div 中,我希望 div 的高度基于百分比值(以 content-div 的 heihgt 作为父级)。我不知道该怎么做?
【问题讨论】:
对于页脚粘在屏幕底部或内容底部(以离顶部较远者为准)的解决方案,请查看 Ryan Fait 的“粘性页脚”。它是一组轻量级且健壮的 CSS,通常是您想要的布局。
【讨论】:
#header {
position:absolute;
height: 50px;
left:0;
top:0;
width:100%;
background:green;
}
#footer {
position:absolute;
height: 50px;
left:0;
bottom:0;
width:100%;
background:green;
}
#content {
position: absolute;
top:50px;
bottom:50px;
left:0;
width:100%;
background:#eee;
}
#box1 {
height:50%;
width:30%;
float:left;
background:red;
}
【讨论】:
overflow css 属性添加到#content。查看实际操作:jsbin.com/erawu3/63
.header {
position: absolute;
height: 50px;
left: 0;
top: 0;
right: 0;
}
.footer {
position: absolute;
height: 50px;
left: 0;
bottom: 0;
right: 0;
}
.content {
position: absolute
top: 50px;
left: 0px;
right: 0px;
bottom: 50px;
}
.box1 {
width: 30%;
height: 50%;
}
【讨论】: