I have tried to add background on header (thead
) with the help of pseudo element (:after
) because i need to display background to one edge to another edge (including both left and right side padding) but thead is not taking position relative and thead
background which is coming from pseudo element (:after
) is relative to the body
, because of this background showing on whole body
.
Here is my code
.table-wrapper {
padding: 0 25px;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,
th {
text-align: left;
padding: 8px;
}
thead {
position: relative;
}
thead:after {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
display: block;
background-color: #c1c1c1;
height: 100%;
z-index: -1;
}
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Email Address</th>
<th>Indicator</th>
<th>Position</th>
<th>Mobile</th>
<th>Status</th>
<th>Created On</th>
<th>Last Login</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
<td>January</td>
<td>$100</td>
<td>January</td>
<td>$100</td>
<td>January</td>
<td>$100</td>
<td>January</td>
</tr>
<tr>
<td>January</td>
<td>$200</td>
<td>January</td>
<td>$100</td>
<td>January</td>
<td>$100</td>
<td>January</td>
<td>$100</td>
<td>January</td>
</tr>
</tbody>
</table>
</div>