【发布时间】:2010-04-29 22:23:15
【问题描述】:
我希望能够设置表格的高度,如果单元格比表格大,则强制单元格单独滚动。
考虑以下代码:(查看它的实际操作here)
<div style="display: table; position: absolute;
width: 25%; height: 80%; min-height: 80%; max-height: 80%;
left: 0%; top: 10%; right: 75%; bottom: 10%; border: solid 1px black;">
<div style="display: table-row;">
<div style="display: table-cell; border: solid 1px blue;">
{Some dynamic text content}<br/>
This cell should shrink to fit its contents.
</div>
</div>
<div style="display: table-row;">
<div style="display: table-cell; border: solid 1px red;
overflow: scroll;">
This should only take up the remainder of the table's vertical space.
This should only take up the remainder of the table's vertical space.
This should only take up the remainder of the table's vertical space.
This should only take up the remainder of the table's vertical space.
This should only take up the remainder of the table's vertical space.
This should only take up the remainder of the table's vertical space.
This should only take up the remainder of the table's vertical space.
This should only take up the remainder of the table's vertical space.
</div>
</div>
</div>
如果您打开此代码(在 IE8 中,在我的例子中),您会注意到第二个单元格在浏览器最大化时很好地适合表格。理论上,当您缩小浏览器(也强制表格缩小)时,当表格变得太小而无法容纳所有内容时,垂直滚动条应该出现在第二个单元格内。但实际上,表格只是垂直增长,超出了 CSS height 属性设置的范围。
希望我已经充分解释了这种情况......
有人知道我怎样才能让它工作吗?
【问题讨论】:
-
你不能用普通的桌子来做这件事吗?看起来非常hacky。
-
@fig-gnuton:实际上,普通的桌子也不起作用(更不用说多么陈旧了)。我尝试过的 HTML 表格一开始就没有响应设定的高度,更不用说正确滚动了。这可能与我在一堆由 ASP.NET 提供支持的更现代的 XHTML 代码中间使用它们有关。我从来没有亲眼见过 HTML 表格在那种情况下表现得很好......
-
Giffyguy,注意到,发布答案。
标签: html css scroll rendering css-tables