I am working on building a view that has two tables which are side by side inside a scrollable div. Both tables have the same height, and the same number of rows. Currently, both tables scroll together in unison.
What i want, is to have both table headers be sticky and remain visible while scrolling the two table body's in sync.
These tables are displayed inside a angular material mat-dialog window.
Some example code:
<div mat-dialog-content class="card-content-view-mode">
<div class="container-fluid">
<div class="row">
<div class="col-6">
<div class="table-container">
<table role="table" class="table leftTable">
<thead>
<th role="col" style="min-width: 100px;">Col 1</th>
<th role="col" style="min-width: 100px;">Col 2</th>
<th role="col" style="min-width: 110px;">Col 3</th>
<th role="col" style="min-width: 100px;">Col 4</th>
<th role="col" style="min-width: 100px;">Col 5</th>
<th role="col" style="min-width: 100px;">Col 6</th>
<th role="col" style="min-width: 100px;">Col 7</th>
</thead>
<tbody>
<tr *ngFor="...">
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-6">
<div class="table-container">
<table role="table" class="table rightTable">
<thead>
<th role="col" style="min-width: 100px;">Col 1</th>
<th role="col" style="min-width: 100px;">Col 2</th>
<th role="col" style="min-width: 110px;">Col 3</th>
<th role="col" style="min-width: 100px;">Col 4</th>
<th role="col" style="min-width: 100px;">Col 5</th>
<th role="col" style="min-width: 100px;">Col 6</th>
<th role="col" style="min-width: 100px;">Col 7</th>
</thead>
<tbody>
<tr *ngFor="...">
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
My CSS styling so far:
.table-container {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
overflow-x: scroll;
border-radius: 10px;
}
Is there a simple way with CSS to specify, perhaps with the sticky property, to have both table headers be sticky and remain at the top of the table-container
div while scrolling?
So far, i have not been able to find any examples online matching my exact use case, so am turning here for help.