Nth-child() does not work as I thought

Hello everyone!
When I use nth-child, it does not work as I expected. I set the (odd) or (2n+1) value of the attribute for background color, but instead of colouring an odd row, it affects cells that make part of the even row.

Here is the code:
tr:nth-child(odd) {
background-color: #fcba7a;

Here is the problem that I’m writing about:

Could you help me, please?

Should I use classes instead nth-child()?

P.S. This table comes from the Chapter 13 of Headfirt HTML and CSS.

We would need to see the HTML for the table to know exactly what is going on here. I’m assuming you have a tr nested within a tr.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.