JSFiddle - React, Tailwind, and code Playground
by Matsunaga_Ajike
HTML
<table class="sticky_table">
<thead>
<tr>
<th></th>
<th>head</th>
<th>head</th>
<th>head</th>
</tr>
</thead>
<tbody>
<tr>
<th>left</th>
<td>data</td>
<td>data</td>
<!-- ... -->
</tr>
<!-- ... -->
</tbody>
</table>
CSS
.sticky_table thead th {
/* 縦スクロール時に固定する */
position: -webkit-sticky;
position: sticky;
top: 0;
/* tbody内のセルより手前に表示する */
z-index: 1;
}
.sticky_table th:first-child {
/* 横スクロール時に固定する */
position: -webkit-sticky;
position: sticky;
left: 0;
}
.sticky_table thead th:first-child {
/* ヘッダー行内の他のセルより手前に表示する */
z-index: 2;
}