我有一张要冻结前三列的表。它通过在列上设置sticky
来起作用,但是这要求我也对它们设置固定的宽度/宽度,这是我要避免的。有没有一种方法可以对前三列进行分组,而仅对分组设置粘性?
这是不正确的,但也许会让您对我的追求有所了解:
body {
font-family: 'Lucida Grande';
}
div {
width: 500px;
height: 200px;
overflow: scroll;
}
td,
th {
padding: 2px 5px;
white-space: nowrap;
}
colgroup {
position: sticky;
position: -webkit-sticky;
left: 0;
background: #569CA8;
color: white;
z-index: 1;
}
<div>
<table cellspacing="0">
<tbody>
<tr>
<colgroup>
<td>Sticky 1</td>
<td>Sticky 2</td>
<td>Sticky 3</td>
</colgroup>
<td>Column 4</td>
<td>Column 5</td>
<td>Column 7</td>
<td>Column 8</td>
<td>Column 9</td>
<td>Column 10</td>
</tr>
<tr>
<colgroup>
<td>Sticky 1</td>
<td>Sticky 2</td>
<td>Sticky 3</td>
</colgroup>
<td>Column 4</td>
<td>Column 5</td>
<td>Column 7</td>
<td>Column 8</td>
<td>Column 9</td>
<td>Column 10</td>
</tr>
</tbody>
</table>
</div>