【发布时间】:2020-05-14 20:47:54
【问题描述】:
我有一个如下表,其中 tbody 内的第一行包含列标题(我这样做是为了使列宽与 td 单元格的宽度匹配)
我想让第一行 row-header 在表格顶部浮动而不破坏列的宽度。
位置 absolute 和 sticky 似乎不起作用。
.rdp-table {
text-align: left;
background-color: #fff;
border-collapse: collapse;
margin: 0 auto;
overflow: scroll;
}
.rdp-table tbody {
max-height: 600px;
overflow-y: scroll;
}
.rdp-table tr {
border: 1px solid #ccc;
}
.rdp-table tr:hover {
background-color: #f5f5f5;
}
.rdp-table th,
.rdp-table td {
font-weight: 600;
line-height: 24px;
border: 1px solid #cecece;
min-width: 128px;
text-align: center;
}
.rdp-table th {
text-align: center;
color: black;
text-transform: uppercase;
}
<table id="table" class="rdp-table">
<tbody>
<tr class="row-header">
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Column 6</th>
</tr>
<tr>
<td>Some really looong looong text that takes the whole table</td>
<td>Value 1</td>
<td>Value 2</td>
<td>Value 3</td>
<td>Value 4</td>
<td>Value 5</td>
</tr>
<tr>
<td>Some really looong looong text that takes the whole table</td>
<td>Value 1</td>
<td>Value 2</td>
<td>Value 3</td>
<td>Value 4</td>
<td>Value 5</td>
</tr>
<tr>
<td>Some really looong looong text that takes the whole table</td>
<td>Value 1</td>
<td>Value 2</td>
<td>Value 3</td>
<td>Value 4</td>
<td>Value 5</td>
</tr>
</tbody>
</table>
【问题讨论】:
标签: javascript html css html-table datatables