我希望能夠設置表格的高度,並強制單元格單獨滾動,如果它們大於表格。如何製作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