How to make it so that the first td with the active class is red, and the second one is yellow
table tr td.active {
background: red;
}
<div class="wrapper">
<table>
<tr>
<td class="cell">1</td>
<td class="cell">2</td>
<td class="cell">3</td>
</tr>
<tr>
<td class="cell active">4</td>
<td class="cell in-range">5</td>
<td class="cell in-range">6</td>
</tr>
<tr>
<td class="cell in-range">7</td>
<td class="cell active">8</td>
<td class="cell">9</td>
</tr>
</table>
</div>
3
Answers
You can select the second child with
nth-child()
.In pure CSS you may use
:has()
(but it has limited support) and detect every .active element except the first one.You will only be able to do it with JS:
DEMO