6
How to apply the scrollbar
(scrollbar) only in the element tbody
, thus leaving the element caption
and thead
fixed on the table, without moving when the scrollbar
moves.
Below follows the HTML
and CSS
table:
body {
font-size: 12px;
font-family: arial;
}
.text-right {
text-align: right;
}
.text-center {
text-align: center;
}
.table {
border-collapse: collapse;
background-color: #fff;
width: 100%;
}
.table caption {
background-color: #222;
color: #fff;
font-size: 14px;
padding: 5px 0;
}
.table th,
.table td {
padding: 5px;
}
.table thead {
background-color: #333;
color: #fff;
height: 40px;
}
.table tbody tr {
border-bottom: 1px solid #999;
}
<table class="table">
<caption>Notas</caption>
<thead>
<tr>
<th>Avaliação 1:</th>
<th>Avaliação 2:</th>
<th>Trabalho:</th>
<th>Avaliação Substitutiva:</th>
<th>Nota Final:</th>
<th>Falta(s):</th>
<th>Situação:</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
<tr>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-right">10</td>
<td class="text-center">-</td>
<td class="text-right">10</td>
<td>0</td>
<td>Aprovado</td>
</tr>
</tbody>
</table>
I did https://jsfiddle.net/vqfmrj1x/1/, but I suspect it’s not quite what you want... Or is it?
– Miguel
No, tbody would have to be below thead, and caption is Fixed as well.
– Yure Pereira
That way I’ve tried too.
– Yure Pereira