roiwew roiwew - 4 years ago 98
CSS Question

Universal selector instead of comma separated elements

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;}

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download