我希望制作一个固定头部和可滚动内容区域的网页。当头部高度已知时,这很简单,但是当头部是流体时,我很难找到解决方案。
我想要的布局是:
--------------
head
--------------
content
--------------
“head”是其内容所需高度,“content”没有最小高度,但在达到视口底部的最大高度之前将成为可滚动的。
现在纯CSS是否可以实现这一点?我针对IE8+。
为了澄清我的意思,这里是如果我知道标题高度我会怎么做:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
margin: 0;
}
#head {
background: yellow;
height: 20px; /* I can't rely on knowing this. */
}
#content {
background: red;
position: absolute;
top: 20px; /* here also */
bottom: 0;
width: 100%;
overflow: auto;
}
</style>
</head>
<body>
<div id="head">some variable height content</div>
<div id="content">
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
</div>
</body>
</html>