【发布时间】:2011-06-20 16:22:43
【问题描述】:
我正在尝试制作一个带有固定标题和可滚动内容区域的网页。当标题具有已知高度时,这很简单,但我正在努力寻找标题流动时的解决方案。
我想要的布局是:
--------------
head
--------------
content
--------------
其中“head”是其内容所需的任何高度,“content”没有最小高度,但会在变为可滚动之前达到视口底部的最大高度。
这些天在纯 CSS 中可能吗?我的目标是 IE8+。
为了澄清我想要什么,here is what I would do if I knew the height of the header:
<!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>
【问题讨论】:
-
你想要滚动条在内容旁边,还是沿着整个页面的高度?
-
如果标题是“固定的”,它的高度是什么?
-
滚动条最好在内容旁边。当我说固定时,我的意思是在位置上,即。它不会随着主要内容滚动。
-
我为固定高度的情况添加了一个示例,以显示我想要的内容。尝试调整视口的大小以查看它的作用。
-
@David:添加了一个 jsFiddle 链接,以便人们看到。您在这里寻找什么样的兼容性?
标签: css