css中设置html的外部样式表的奇偶行交替色类似

html-css014

css中设置html的外部样式表的奇偶行交替色类似,第1张

可以啊,用css3或者jq实现。

可以使用css3的奇偶选择器,如:

tr:nth-child(odd){background-color:#FFE4C4}

tr:nth-child(even){background-color:#F0F0F0}

li:nth-child(odd)是设置奇数行的背景色,li:nth-child(even)是设置偶数行的。但是css3不兼容IE9以下的浏览器,如果需要考虑到兼容问题的话,可以使用jq设置,如:

$("table  tr:nth-child(even)").css("background-color","#FFE4C4")    //设置偶数行的背景色

$("table  tr:nth-child(odd)").css("background-color","#F0F0F0")    //设置奇数行的背景色

jQuery中设置html的外部样式表的奇偶行交替色类似:

设置偶数行的背景色:$("table  tr:nth-child(even)").css("background-color","#FFE4C4")

设置奇数行的背景色:$("table  tr:nth-child(odd)").css("background-color","#F0F0F0") 

可以使用css3的奇偶选择器:

tr:nth-child(odd){background-color:#FFE4C4}。

tr:nth-child(even){background-color:#F0F0F0}li:nth-child(odd)是设置奇数行的背景色,li:nth-child(even)是设置偶数行的。

参考资料

jQuery中设置html的外部样式表的奇偶行交替色类似.博客[引用时间2018-1-5]