Skip to content

Instantly share code, notes, and snippets.

@kdssoftware
Last active November 26, 2020 10:47
Show Gist options
  • Save kdssoftware/5d2185587f1bd51c984b9ea431f2c08c to your computer and use it in GitHub Desktop.
Save kdssoftware/5d2185587f1bd51c984b9ea431f2c08c to your computer and use it in GitHub Desktop.
Scrollable table with sticky header. Only essentials css ( https://jsfiddle.net/xfoph4ne/ )
main{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#content{
height: 100%;
display: flex;
flex-direction: column;
}
.table-wrapper{
overflow-y: scroll;
}
.table-wrapper th{
position: sticky;
top: 0;
}
table{
border-collapse: collapse;
}
<main>
<div id="content">
<p>content before</p>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Header</th>
<th>Header</th>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
</tr>
<!-- ... -->
<tr>
<td>Text</td>
<td>Text</td>
<td>Text</td>
</tr>
</tbody>
</table>
</div>
<div>content after</div>
</div>
</main>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment