To resolve the issue, include border-collapse: separate;
in the table. This will style your borders to align with the <td>
elements and ensure that they are truly connected to the <td>
, resulting in a collapsed
appearance.
Additionally: don't forget to add border-spacing: 0;
to the table to eliminate any padding for the table cells.
table{
border-collapse: separate;
border-spacing: 0;
}
td{
border:3px solid gray;
padding:3px;
}
tbody td{
background:lightgreen;
}
.sticky{
background:maroon;
color:white;
position:sticky;
top:0;
}
<table>
<thead>
<tr>
<td class="sticky">This is sticky header
<td class="sticky">This is sticky header
<td class="sticky">This is sticky header
<td class="sticky">This is sticky header
<tbody>
<tr><td>Some random text
<tr><td>Some random text
... <!-- additional rows of random text -->
</table>