A simple way to achieve this is by utilizing CSS pseudo classes such as :nth-child(odd)
and nth-child(even)
to style elements accordingly.
Check out the demo here
td {
border: 1px solid #000;
}
tr:nth-child(odd) {
height: 150px;
}
If you wish to target the even elements, you can use the even
keyword like so:
tr:nth-child(even) {
height: 150px;
}
Remember that these selectors will affect all tr
and td
elements on your page, so it's advisable to assign a unique class
or id
to your table
for more specific targeting. Here's an example:
.unique-table-class tr:nth-child(odd) {
/* Your styles here */
}