将文本颜色应用于 HTML 列

The*_*nda 5 html css html-table col

<table>
    <colgroup>
        <col style="color: green"/>
        <col style="background-color:green"/>
        <col class="char"/>
    </colgroup>
    <tr>
        <th>
            Decimal
        </th>
        <th>
            Hex
        </th>
        <th>
            Char
        </th>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我一生都无法弄清楚为什么 Decimal 不是绿色的!

我需要整个列都是绿色字体,背景颜色出于某种原因起作用。

有没有办法在不向每个 tr 添加类的情况下做到这一点?

我需要能够为每一列应用不同的颜色。

Gau*_*aik 3

th 在 tr 内部,因此它不采用字体颜色。

这是我的解决方案,它不是一个完美的解决方案,但不必添加单独的类。

th:first-child {
  color: green;
}

th:nth-child(2) {
  color: yellow;
}
Run Code Online (Sandbox Code Playgroud)
<table>
  <colgroup>
    <col style="color: green" />
    <col style="background-color:green" />
    <col class="char" />
  </colgroup>
  <tr>
    <th>
      Decimal
    </th>
    <th>
      Hex
    </th>
    <th>
      Char
    </th>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)