2

I want to style both th and td elements in such table:

<table>
  <tr>
    <th>Abc</th>
    <td>Cde</td>
  </tr>
  <tr>
    <th>Abc</th>
    <td>Cde</td>
  </tr>
</table>

I don't want to add class to it, so I need to do it like that:

tr td, tr th{background:#dddddd;}
tr:nth-child(even) td, tr:nth-child(even) th{background:#ffffff;}

But... are there any disadvantages to doing it that like below?

tr > *{background:#dddddd;}
tr:nth-child(even) > *{background:#ffffff;}
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
roiwew
  • 65
  • 4
  • 1
    I don't see any problem in doing this, since the only immediate children are `td` and `th`. If your concern is in regards to the performance read this answer [here](http://stackoverflow.com/a/13432169). – Nikhil Girraj Feb 02 '17 at 09:11

1 Answers1

1

No; at worst you'll just get yelled at by people who still subscribe to the "avoid the universal selector" dogma. If you're still worried, because your pages are extremely complex with elements in the order of thousands, then you can choose not to use it, but you'll just have to make do with the expanded selector-list because there isn't any cross-browser alternative available.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356