我有一个HTML表,在其页脚2行,垂直和水平滚动工作正常,但我想保持页脚行固定之一(不滚动),以显示分页控件。
我想知道这是否可能只使用CSS。我已经尝试将display
和position
属性更改为第二行,但没有预期的结果。
/* Center the grid container */
.container {
width: 800px;
height: 600px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* Grid style */
#grid {
margin-top: 25px;
position: relative;
left: 50%;
transform: translateX(-50%);
width: 70%;
max-width: 90%;
min-width: 400px;
overflow: hidden;
height: auto;
max-height: 473px;
}
/* Table size */
table {
height: 388px;
margin: 0 auto !important;
display: block;
overflow-x: auto;
border-spacing: 0;
}
tbody {
white-space: nowrap;
}
.caption {
padding: 10px 10px 0px 10px;
font-weight: bold;
background: #b3b3b3;
border-bottom: 1px solid #c8c6c6;
position: sticky;
top: 0;
z-index: 2;
}
/* Columns style */
th {
background: #b3b3b3 !important;
vertical-align: bottom;
text-transform: capitalize;
}
th.fixed {
position: sticky;
right: 0;
z-index: 2;
}
td.fixed {
position: sticky;
right: 0;
z-index: 1;
}
/* Header & Footer row style */
thead tr {
position: sticky;
top: 0;
z-index: 2;
}
tfoot {
position: sticky;
z-index: 2;
bottom: 0;
}
个字符
1条答案
按热度按时间ht4b089n1#
你可以做到这一点,但它是一种hacky地狱。
把页脚内容放在第一个
td
中,然后有一个空的td
,它跨越了其他列。给予你的页脚tdposition:sticky; left:0;
和(重要的是)white-space:nowrap
,因为我们希望内容扩展到它的单元格之外,并粘在一边。例如:
个字符
但是为什么要这么麻烦呢?您可以将分页内容放在
table
* 外部 * 的div
中,而不是放在tfoot
中。