Nth-child (even) always selects dd, never dt (even and odd lines in dl)

I am trying to bring the appearance of a table to a list of definitions and want the even lines to differ from the odd ones with some css3 selectors.

#specs dt:nth-child(even), #specs dd:nth-child(even) { background: blue; } 

This css code results in dt without backgroundcolor, and each dd in blue. As I can see, the rendering engine actually counts siblings different from the selected ones, which leads to the fact that every dt is odd and every dd is even.

+4
source share
2 answers

If I understand correctly, you can do this using the nth-of-type selector:

 #specs dt:nth-of-type(even), #specs dd:nth-of-type(even) { background: blue; } 

See: http://jsfiddle.net/5Zjqh/

+17
source

That is how it is. If you want, you can try "nth-child (4n + 1)"

0
source

Source: https://habr.com/ru/post/1344701/


All Articles