1

tr.whois:nth-child(even) {
  background-color: black;
}

.hide {
  display: none;
}
<tr class="whois">row 1</tr>
<tr class="whois">row 2</tr>
<tr class="hide">row 3</tr>
<tr class="whois">row 4</tr>
<tr class="whois">row 5</tr>

here visible row (1,2,4,5) and nth-chid(even) makes black (1,3,5)-

enter image description here

But I need this-

enter image description here

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121

1 Answers1

1

You can do something like this:

Since you have hide element as well so this is the place where you have to use ~(negate) for odd and even The code is pretty straight forward to understand let me know if you need explaination.

.whois {
  background: green;
  color: white;
}

.whois:nth-child(even) {
  background: black;
  color: white;
}

.whois.hide {
  display: none;
}

.whois.hide~.whois:nth-child(odd) {
  background: black;
  color: white;
}

.whois.hide~.whois:nth-child(even) {
  background: green;
  color: white;
}
<table>
  <tr class="whois">
    <td>row 1</td>
  </tr>
  <tr class="whois">
    <td>row 2</td>
  </tr>
  <tr class="whois hide">
    <td>row 3</td>
  </tr>
  <tr class="whois">
    <td>row 4</td>
  </tr>
  <tr class="whois">
    <td>row 5</td>
  </tr>
</table>
Manjuboyz
  • 6,978
  • 3
  • 21
  • 43