我有一个带有固定页脚和页眉的布局,我想要的是“信息框”div 的高度可变,并让“滚动 div”填充右列中剩余的垂直高度。从这个 fiddle可以看出,如果我将 scrolling-div 的高度设置为 100%,它将变得与右列一样高,而不是剩余空间。
这是页面的 HTML:
<body>
<div id="header">
</div>
<div id="main-container">
<div id="page-content">
<div id="left-column">
</div>
<div id="right-column">
<div id="info-box">
This is a variable height div</div>
<div id="scrolling-div">
Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br /> Loads and loads of scrolling content<br /><br />
</div>
</div>
</div>
</div>
<div id="footer">
</div>
</body>
这是CSS:
body {
height:100%;
width:100%;
margin:0;
padding:0;
}
#header {
position:fixed;
height:45px;
width:100%;
background-color:#FF0000;
top:0;
}
#footer {
position:fixed;
height:45px;
width:100%;
background-color: #FF00FF;
bottom:0
}
#main-container {
background:#00FF00;
position:absolute;
top:45px;
bottom:45px;
width:100%
}
#page-content {
width:960px;
position:relative;
margin: 0 auto;
background-color:#FFF000;
height:100%;
}
#left-column {
background-color:#444444;
width:400px;
height:100%;
float:left;
}
#right-column {
background-color:#0000FF;
float:right;
width:560px;
z-index:10000;
height:100%;
}
#info-box {
width:100%;
height:200px;
background-color:#0F0F0F;
color: #FFFFFF;
}
#scrolling-div {
background-color:#FFFFFF;
height:200px;
overflow:scroll;
}
再一次,一个指向小提琴的链接可以看到它的实际效果。
谢谢你的帮助!