我正在寻找一个 HTML/CSS 解决方案,其中内部 DIV 具有以下特征:
一定有:
- 包含在可变高度同级标题 div 下方的固定高度容器 div 中。
- 填充可用的可变高度,没有 max-height CSS 属性
- 必要时垂直滚动以容纳内容
- 位于 DOCTYPE = HTML 4.01 strict 的文档中(如有必要,最好使用 HTML 5)
- 兼容多浏览器(Chrome、Firefox、IE、Safari、手机浏览器)
想拥有:
- 不使用表格
- 不使用 JavaScript
到目前为止,我有以下部分解决方案:
- 仅限 WebKit,带表格:http: //jsfiddle.net/ksevksev/PBXZG/2/
HTML
<div class="parent">
<table cellspacing="0">
<tr><td class="header">Heading</td></tr>
<tr><td class="scrollContainer"><div class="innerScroll">
Lots of text goes here. Lots of text goes here. Lots of text goes here.
...
Lots of text goes here. Lots of text goes here. Lots of text goes here.
</div>
</td></tr>
</table>
</div>
CSS
.parent
{
margin:0px;
padding:0px;
height: 400px;
background-color: orange;
border: thick purple solid;
}
table
{
border:green thick solid;
width:100%;
height:100%;
margin:0px;
}
.header
{
font-weight: bold;
font-size: 28pt;
font-family: sans-serif,Arial;
border:yellow thick solid;
}
.scrollContainer
{
margin: 0px;
position: relative;
border: thick blue solid;
bottom:0px;
top:0px;
left:0px;
right: 0px;
height:100%;
}
.innerScroll
{
overflow-y: auto;
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
- 带有 jQuery 的多浏览器:http: //jsfiddle.net/ksevksev/yDJrV/1/
HTML
<div class="parent">
<div class="header">Heading</div>
<div class="scrollContainer">
<div class="innerScroll">
Lots of text goes here. Lots of text goes here. Lots of text goes here.
...
Lots of text goes here. Lots of text goes here. Lots of text goes here.
</div>
</div>
</div>
CSS
.parent
{
margin:0px;
padding:0px;
height: 400px;
background-color: orange;
border: thick purple solid;
}
.header
{
font-weight: bold;
font-size: 28pt;
font-family: sans-serif,Arial;
border:yellow thick solid;
}
.scrollContainer
{
position: relative;
border: thick blue solid;
bottom:0px;
top:0px;
left:0px;
right: 0px;
height:100%;
}
.innerScroll
{
position: absolute;
overflow-y: auto;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
JS
var container = $(".scrollContainer");
var header = $(".header");
var parent = $(".parent");
var containerHeight = parent.innerHeight() - header.outerHeight();
//alert("containerHeight=[" + containerHeight + "]");
container.outerHeight(containerHeight);
预先感谢您的帮助!