How can I make a table header sticky to the main-1
? I have tried creating a working demo with multiple rows but haven't been successful.
HTML: on CodePen: https://codepen.io/jokemail/pen/VwBvNBv
#printGridHeader
{
position: sticky;
top: 6.5em;
z-index:202;
background-color: #ffffff;
}
#printGridTable.th
{
position: sticky;
top: 6.5em;
z-index:202;
background-color: #ffffff;
}
<div id="main-1" class="bootstrap">
<form id="frmSearch_1" method="post">
<div id="printGridHeader" style="text-align:right;margin:20px 0px;">
This also has to be sticky and currently is
</div>
<div id="tableDiv" style="overflow-x:auto;">
<table class="table table-hover" id="printGridTable" style="overflow-x:auto;width:100%;">
<thead>
<tr id="printGridTable_head">
<th scope="col" width="40px">Nr.</th>
<th scope="col" width="40px">Nr.</th>
</tr>
</thead>
<tbody>
<tr class="table-row">
<td width="40px">1.</td>
<td>126</td>
</tr>
<tr class="table-row">
<td width="40px">1.</td>
<td>126</td>
</tr>
<tr class="table-row">
<td width="40px">1.</td>
<td>126</td>
</tr>
<tr class="table-row">
<td width="40px">1.</td>
<td>126</td>
</tr>
<tr class="table-row">
<td width="40px">1.</td>
<td>126</td>
</tr>
<tr class="table-row">
<td width="40px">1.</td>
<td>126</td>
</tr>
<tr class="table-row">
<td width="40px">1.</td>
<td>126</td>
</tr>
</tbody>
</table>
</div>
</form>
</div>