我希望能够设置表格的高度,并强制单元格单独滚动,如果它们大于表格。如何制作CSS定义的表格单元格滚动条?
考虑下面的代码:(看到它在行动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
属性设置的界限。
希望我已经解释了此方案充分...
有谁知道我能得到这个工作?
你不能用普通表做到这一点?似乎非常哈克。 – fig 2010-04-29 22:27:06
@ fig-gnuton:实际上,一张普通的桌子也不起作用(更不用说古代了)。我尝试过的HTML表格从来没有对设置的高度作出响应,更不用说正确滚动了。这可能与我在一堆由ASP.NET支持的更为现代的XHTML代码中间使用它们有关。我从来没有亲眼见过HTML表格在这种情况下很好玩...... – Giffyguy 2010-04-29 22:30:47
Giffyguy,注意到,发布了一个答案。 – fig 2010-04-29 22:35:21