HTML同类型元素选择器nth-of-type实现表格隔行换色
<style type="text/css">
table tr:nth-of-type(odd) {
background: deepskyblue;
}
table tr:nth-of-type(even) {
background: skyblue;
}
</style>
注意:
① nth-child为非同类型元素选择器,执行能力强但容易发生混选(当往之前的元素间再插入其他元素时选择顺序会被打乱)。
② nth-of-type为同类型元素选择器,相比非同类型其分辨能力更强,推荐使用。
③ odd 和 2n + 1表示选中奇数行,even 和 2n表示选中偶数行。
还没有评论,来说两句吧...