国际象棋 table 没有伪 类

chess table without pseudo classes

如果我不能更改 HTML 代码,我如何创建国际象棋 table,只添加 STYLE 标签中的样式,将 table 引导到表格中,是如右图所示。伪选择器 :Not,:nth-child(i),:nth-child(an+b),:nth-of-type(i),:nth-of-type(an+b)都没有用

Table 是 10*10。我只能创建绿色边框。我只需要国际象棋标记(白色和黑色)。

<style>     
  table.ches td
  {
    width: 100px;
    height: 100px;
    border: solid black 2px;
  }

 table.ches  tr :first-child{background:  green;
    color:  black;}

    table.ches tr:first-child>td {background:  green;
    color:  red;}

     table.ches tr:last-child>td {background:  green;
    color:  black;}

     table.ches  tr :last-child{background:  green;
    color:  black;}

</style>

<table class="ches">
<tbody><tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
  <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
</tbody></table>

</body>

虽然nth-of-type(i)nth-of-type(an + b)不被允许,但我猜这并不意味着nth-of-type(even|odd)出局了?如果是这样,CSS 很简单:只需将偶数 tr 内的所有偶数 td 和奇数 tr 内的所有奇数 td 设为黑色:

tr:nth-of-type(even) td:nth-of-type(even),
tr:nth-of-type(odd) td:nth-of-type(odd) {
    background: black;
}

这是一个工作 JSFiddle。干杯!