I have a table with no fixed td widths and table width set to 100%. I want the table header to be fixed. I have found many solutions for fixed width like this one: JSFiddle
But it doesnt work for fluid width table, and when you decrease the viewport size it fails to achieve the functionality.
Any way to achieve responsive fixed width header?
My HTML is like this:
<table class="delegations-table">
<thead>
<tr class="del-head">
<th>Région</th>
<th>Ville / Quartier</th>
<th>Lien</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#">Région de Rabat-Salé-Zemmour-Zaer</a></td>
<td><a href="#">Délégation de Rabat</a></td>
<td><a href="#"><img src="img/icons/del-icon.png" alt="" /></a></td>
</tr>
<tr>
<td><a href="#">Région de Rabat-Salé-Zemmour-Zaer</a></td>
<td><a href="#">Délégation de Sale</a></td>
<td><a href="#"><img src="img/icons/del-icon.png" alt="" /></a></td>
</tr>
<tr>
<td><a href="#">Région de Rabat-Salé-Zemmour-Zaer</a></td>
<td><a href="#">Délégation de Temara</a></td>
<td><a href="#"><img src="img/icons/del-icon.png" alt="" /></a></td>
</tr>
<tr>
<td><a href="#">Région de Rabat-Salé-Zemmour-Zaer</a></td>
<td><a href="#">Délégation de Touraga</a></td>
<td><a href="#"><img src="img/icons/del-icon.png" alt="" /></a></td>
</tr>
</tbody>
</table>
My CSS is as follows:
.del-contain {
max-height: 260px;
width: 100%;
overflow: auto;
}
.delegations-table {
width: 94%;
margin: auto;
position: relative;
}
.delegations-table th {
color: #FFF;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
padding-left: 18px;
line-height: 2;
}
.delegations-table tr td a {
display:block;
height:100%;
width:100%;
}
.delegations-table tr.del-head {
background: #3b8d3c!important;
}
.delegations-table td {padding: 5px 0 10px 18px;}
.delegations-table tr:hover {background: #ededed;}
.delegations-table td a {color: #000;}
.delegations-table td a:hover {text-decoration: none;}