Give this selector a try
table tr:nth-of-type(4n) td {
border-bottom: 3px solid #f00;
}
Explanation : This selector targets every fourth row within a table by first selecting the table
element and using the :nth-of-type(4n)
pseudo-class. It then applies styles to the td
element in that specific row. You can customize the borders with properties like border-bottom
, border-top
, or simply use border
for all sides of the td
element.
Check out the Demo
See Demo 2 (CSS Normalized)
This method allows you to avoid adding extra classes to your elements.
If needed, here is the HTML code:
<table>
<tr>
<td>First</td>
<td>Second</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
</tr>
<tr>
<td>First</td>
<td>Second</td>
</tr>
</table>
Note: The provided selector will target all tables on your website. To apply styles to a specific table, consider assigning a class to it and use a more specific selector, as shown below:
table.class_name tr:nth-of-type(4n) td {
/* Styles */
}