开发者

nth-child(even) always selecting dd, never dt (even and odd lines in dl)

开发者 https://www.devze.com 2023-02-19 07:15 出处:网络
I\'m trying to give a table appearance to a definition list and want to have the even lines colored differently from the odd ones with the help of some css3 selectors.

I'm trying to give a table appearance to a definition list and want to have the even lines colored differently from the odd ones with the help of some css3 selectors.

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

This css code results in dt's without backgroundcolor and every dd being colored blue. The way I see it the render engine is actually counting siblings other than the ones selected too, resulting in every dt being odd and 开发者_Go百科every dd being even.


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/


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

0

精彩评论

暂无评论...
验证码 换一张
取 消