I am interested in developing a scrolling table where only 10 rows are visible at any given time, with the middle row set to stand out even during scrolling.
The concept is that as the user scrolls down, the highlighted row changes progressively as they continue to scroll.
I have created a simple table where the middle row is highlighted. However, I would like the highlighted class to shift to the next row when scrolling starts, creating the effect of always highlighting the middle row.
table {
max-width: 980px;
table-layout: fixed;
margin: auto;
}
th, td {
padding: 5px 10px;
border: 1px solid #000;
}
thead, tfoot {
background: #f9f9f9;
display: table;
width: 100%;
width: calc(100% - 18px);
}
tbody {
height: 300px;
overflow: auto;
overflow-x: hidden;
display: block;
width: 100%;
}
tbody tr {
display: table;
width: 100%;
table-layout: fixed;
}
.highlighted{
background-color: coral;
}
<body>
<table>
<thead>
<tr>
<th scope="col">Header 1</th>
<th scope="col">Header 2</th>
<th scope="col">Header 3</th>
<th scope="col">Header 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell content</td>
<td>Cell content</td>
<td>Cell content</td>
<td>Cell content</td>
</tr>
<tr>
<td>Cell content</td>
<td>Cell content</td>
<td>Cell content</td>
<td>Cell content</td>
</tr>
<tr>
<td>Cell content</td>
<td>Cell content</td>
<td>Cell content</td>
<td>Cell content</td>
</tr>
<tr>
<td>Cell content</td>
<td>Cell content</td>
<td>Cell content</td>
<td>Cell content</td>
</tr>
<tr>
<td class= "highlighted" >Cell content</td>
<td class= "highlighted" >Cell content</td>
<td class= "highlighted" >Cell content</td>
<td class= "highlighted" >Cell content</td>
</tr>
// Remaining rows omitted for brevity
</tbody>
<tfoot>
<tr>
<td>Footer 1</td>
<td>Footer 2</td>
<td>Footer 3</td>
<td>Footer 4</td>
</tr>
</tfoot>
</table>
</body>