css - 每个 'tr' 都有不同的背景颜色

标签 css

我的 table HTML 下面有 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>

是否可以使用 css 为每个 tr 设置不同的背景颜色,例如使用 nth-child

我试试这个:

    table tr:nth-child(1) {
      background-color:#000
    }

但它不起作用。

最佳答案

试试这个:

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

关于css - 每个 'tr' 都有不同的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25519916/

相关文章:

html - fiddley navigation - 无序列表和背景颜色中的无序列表

javascript在视口(viewport)中找到最近的元素并滚动到它

html - 将自定义 Bootstrap 工具提示气球与轮廓对齐

css - 什么是 Bootstrap 表单控件类?

html - 阻止表格单元格重叠 HTML CSS

html - 下拉菜单 - 元素依赖

css - 当我使用少于 12 列时,如何避免将 Bootstrap 列分解为行?

html - 增加选择菜单选项之间的差距

html - 通过每个元素的中间垂直对齐两个元素

c# 访问所有可用的 css 列表或属性集合