I have the following long table (generated dynamically from database) showing in the whole page. It has vertical and horizontal scroll bars due to the length of the table.
I am able to fix the header in fixed position with the following CSS
code
table {
border-spacing: 0;
width: 100%;
overflow-y: auto;
height: 50vh;
}
thead th {
position: sticky;
top: 0;
background-color: white;
}
But I also want to freeze the left side th
so that when I scroll the horizontal scroll bar, I still can see the left most column. Does anyone know how to do it?
Edit 1
The table I mentioned is generating dynamically. So I can't paste the original code as it contains mix of php
and MySQL
. So for a reference, I am pasting a bootstrap table to work
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
<td>@mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
<td>@fat</td>
</tr>
</tbody>
</table>