如何为单个表格单元格设置背景色?

6 min read

您可以使用CSS样式来为单个表格单元格设置背景色。

使用以下样式:

td {
  background-color: #color;
}

#color 替换为您想要的颜色代码。

如果您只想为特定的单元格设置背景色,可以为该单元格添加一个类或ID,并使用以下样式:

.table-class td.custom-class {
  background-color: #color;
}

或者

#table-id td.custom-class {
  background-color: #color;
}

.table-class#table-id 替换为您表格的类或ID,并将 .custom-class 替换为您要为其添加特定背景色的单元格的类或ID。然后,将 #color 替换为您想要的颜色代码。