CSS Sticky overflow scroll
by amindunited
HTML
<!-- SOF Page Div -->
<div class="page">
<!-- SOF Container Div
This is the Div that centers the content on the page, and sets the Left/right Margins
-->
<div class="container">
<h1>
Container (Red)
</h1>
<div class="section">
<h2>
Section (Blue)
</h2>
<table class="fixed_table">
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
<th>Col 5</th>
</tr>
</thead>
<tbody>
<tr>
<td>row 1-0</td>
<td>row 1-1</td>
<td>row 1-2</td>
<td>row 1-3</td>
<td>row 1-4</td>
</tr>
<tr>
<td>row 2-0</td>
<td>row 2-1</td>
<td>row 2-2</td>
<td>row 2-3</td>
<td>row 2-4</td>
</tr>
<tr>
<td>row 3-0</td>
<td>row 3-1</td>
<td>row 3-2</td>
<td>row 3-3</td>
<td>row 3-4</td>
</tr>
<tr>
<td>row 4-0</td>
<td>row 4-1</td>
<td>row 4-2</td>
<td>row 4-3</td>
<td>row 4-4</td>
</tr>
<tr>
<td>row 5-0</td>
<td>row 5-1</td>
<td>row 5-2</td>
<td>row 5-3</td>
<td>row 5-4</td>
</tr>
<tr>
<td>row 6-0</td>
<td>row 6-1</td>
<td>row 6-2</td>
<td>row 6-3</td>
<td>row 6-4</td>
</tr>
<tr>
<td>row 7-0</td>
<td>row 7-1</td>
<td>row 7-2</td>
<td>row 7-3</td>
<td>row 7-4</td>
</tr>
<tr>
<td>row 8-0</td>
<td>row 8-1</td>
<td>row 8-2</td>
<td>row 8-3</td>
<td>row 8-4</td>
</tr>
<tr>
<td>row...
CSS
html, body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 16px;
background-color: #e8e8e8;
padding: 0;
margin: 0;
}
.page {
width: 100vw;
height: 100vh;
/* overflow-y: auto; */
}
.container {
padding: 0.5rem;
border: solid 1px red;
background-color: #ffffff;
width: 800px;
margin-left: auto;
margin-right: auto;
overflow-x: scroll;
overflow-y: visible;
height: 100vh;
}
.section {
padding: 0.5rem;
border: solid 1px blue;
height: fit-content;
}
td, th {
padding: 0.5rem;
min-width: 20vw;
}
.fixed_table thead {
color: white;
background-color: black;
}
table.fixed_table > thead, table.fixed_table > thead > tr > th {
top: 0px;
position: -webkit-sticky;
position: sticky;
z-index: 1;
}
table {
border: solid 1px green;
}