2012-11-19 30 views

回答

11

用途:第n个孩子()伪类

tr:nth-child(odd){ 
    background-color:green 
} 
tr:nth-child(even){ 
    background-color:yellow 
}​ 

DEMO

Here是几个选择的例子。

+0

@Sowmya:我怎么能删除特定行的BGCOLOR而我用这个解决方案 –

+1

您可以指定样式像TR行号: nth-child(4){style here} http://jsfiddle.net/XUNg3/11/或者您可以为tat行指定类名并为该类指定样式。 – Sowmya

1

您可以使用CSS3选择器nth-child

tr:nth-child(odd) 

代表了HTML表格的奇数行。

1

Demo

使用:nth-of-type(n)伪类

像这样

tr:nth-of-type(2n){ 
    background-color:green 
} 
tr:nth-of-type(2n-1){ 
    background-color:yellow 
} 

Demo

更多信息click here