首页 > 解决方案 > CSS 表格 - 表格的第一个 td 元素的不同颜色,条纹

问题描述

我设法有条纹行,我也设法只为表格的第一个元素着色,但我不能同时做到这两个!

这是我的代码:

.raceresultscss>tbody>tr>td:first-child:nth-of-type(even){
    background-color:black !important;
    color:white;
}

.raceresultscss>tbody>tr>td:first-child:nth-of-type(odd){
    background-color:#94c946 !important;
    color:red;
}

标签: css

解决方案


.raceresultscss>tbody>tr>td:first-child:nth-of-type(even)不存在..第一个孩子总是很奇怪...

你是那个意思吗?

.raceresultscss>tbody>tr:nth-of-type(even)>td:first-child{
    background-color:black !important;
    color:white;
}

.raceresultscss>tbody>tr:nth-of-type(odd)>td:first-child{
    background-color:#94c946 !important;
    color:red;
}
<table class="raceresultscss">
  <tbody>
    <tr>
      <td>0</td><td>A</td><td>B</td><td>C</td>
    </tr>
    <tr>
      <td>1</td><td>A1</td><td>B1</td><td>C1</td>
    </tr>
    <tr>
      <td>2</td><td>A2</td><td>B2</td><td>C2</td>
    </tr>
    <tr>
      <td>3</td><td>A3</td><td>B3</td><td>C3</td>
    </tr>
  </tbody>
</table>


推荐阅读