Skip to content

Instantly share code, notes, and snippets.

@ali-kamalizade
Last active September 21, 2023 12:55
Show Gist options
  • Save ali-kamalizade/ab333e6009bbda0d433b728f5b5d2339 to your computer and use it in GitHub Desktop.
Save ali-kamalizade/ab333e6009bbda0d433b728f5b5d2339 to your computer and use it in GitHub Desktop.
HTML5 table with sticky table headers in supported browsers. Using bulma.css for styling
<main>
<table class="table is-fullwidth">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Job</th>
<th>Color</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
<!-- More table rows -->
<tr>
<td>Lorem.</td>
<td>Ullam.</td>
<td>Vel.</td>
<td>At.</td>
<td>Quis.</td>
</tr>
</tbody>
</table>
</main>
<div class="has-text-right">
<button class="button">Export</button>
</div>
<style>
main {
max-height: 300px;
overflow-y: auto;
}
th {
background: white;
/* See https://caniuse.com/css-sticky */
position: sticky;
/* Don't forget this, required for the stickiness */
top: 0;
z-index: 1;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment