Css 每个';tr';有不同的背景色

Css 每个';tr';有不同的背景色,css,Css,我在我的表格中有tr列表,如下所示: <table> <tr> <td>content here</td> <td>content here</td> <td>content here</td> </tr> <tr> <td>content here</td> <td>content her

我在我的
表格中有
tr
列表,如下所示:

<table>
  <tr>
    <td>content here</td>
    <td>content here</td>
    <td>content here</td>
  </tr>
  <tr>
    <td>content here</td>
    <td>content here</td>
    <td>content here</td>
  </tr>
  <tr>
    <td>content here</td>
    <td>content here</td>
    <td>content here</td>
  </tr>
  <tr>
    <td>content here</td>
    <td>content here</td>
    <td>content here</td>
  </tr>
</table>
但它不起作用。

您可以:

table tr:nth-child(1)>td {
  background-color:#000
}
试试这个:

tr:nth-child(2n+1){
   background-color:#000;
}

它的工作原理如Suresh的小提琴所示,每个
tr
都有不同的背景色,这是绝对可能的,而且您的工作方向是正确的。你的问题更多的是关于如何简化代码,而不是为每个孩子编写一条规则?你想要多少种不同的颜色?不要说答案不正确,但这会为每个tr做斑马条纹,而不是不同的背景颜色。如果你想为每个tr指定一种特定的颜色,然后,您必须手动指定每个tr的背景,或者在查询中,您必须迭代到每个tr,并通过每次在循环内递增颜色值来设置特定的颜色。知道了。。!!您可以使用“蝉原理”(CICADPrinciple)为
tr:nth child(Nn+A)
设置不同的颜色,为
tr:nth child(Mn+B)>td
设置不同的半透明(
rgba
hsla
)色调,从而生成大型图案。在建议代码/解决方案时,您应该简要介绍您建议的解决方案!
tr:nth-child(2n+1){
   background-color:#000;
}