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

html-css013

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")    //设置奇数行的背景色

借助CSS3选择器:nth-child(2n+1)即可

<style>

.list li:nth-child(2n+1) {

background: #39f

}

</style>

<ul class="list">

<li>《HTML5布局之路》</li>

<li>CSS3</li>

<li>特殊选择器</li>

<li>:nth-child()</li>

</ul>