【发布时间】:2017-03-24 01:28:52
【问题描述】:
对于 html 表格,我正在尝试实现 100% 的容器高度以及表格列大小调整功能。 即,当内容高度超过包含 div 的高度(而不是 thead 和 tfoot)时,只有 tbody 应该滚动。并且应该可以调整表格列的大小。 出于某种原因,我只想使用一个表格元素(我不想通过为 thead 和 tbody 使用单独的表格来实现这一点)。
我根据here 给出的建议尝试了以下小提琴
这些是我尝试过的小提琴
1.http://jsfiddle.net/Ld4uv0a4/2/
table.scroll {
/* width: 100%; */ /* Optional */
/* border-collapse: collapse; */
border-spacing: 0;
border: 2px solid black;
}
table.scroll tbody,
table.scroll thead { display: block; }
thead tr th {
height: 30px;
line-height: 30px;
/* text-align: left; */
}
table.scroll tbody {
height: 100px;
overflow-y: auto;
overflow-x: hidden;
}
tbody { border-top: 2px solid black; }
tbody td, thead th {
/* width: 20%; */ /* Optional */
border-right: 1px solid black;
/* white-space: nowrap; */
}
tbody td:last-child, thead th:last-child {
border-right: none;
}
2.https://jsfiddle.net/wwjgozqp/
.table-container {
height: 10em;
}
table {
display: flex;
flex-flow: column;
height: 100%;
width: 100%;
}
table thead {
/* head takes the height it requires,
and it's not scaled when table is resized */
flex: 0 0 auto;
width: calc(100% - 0.9em);
}
table tbody {
/* body takes all the remaining available space */
flex: 1 1 auto;
display: block;
overflow-y: scroll;
}
table tbody tr {
width: 100%;
}
table thead,
table tbody tr {
display: table;
table-layout: fixed;
}
/* decorations */
.table-container {
border: 1px solid black;
padding: 0.3em;
}
table {
border: 1px solid lightgrey;
}
table td, table th {
padding: 0.3em;
border: 1px solid lightgrey;
}
table th {
border: 1px solid grey;
}
但似乎没有任何效果。谁能帮我实现这两种效果(列调整大小和 100% 容器高度)。
【问题讨论】:
标签: javascript css resize css-tables