如何设置数据表列中的单元格样式



我在dataTables中使用jQuery插件创建了一个表(带有子行(。我无法找到如何将样式应用于单个单元格列(<td>(

正如您所看到的,我已经对这个现有的小提琴进行了编辑,我已经在第 2 列中使文本变大,但我也想在第 4 列和第 5 列中使文本变大(加上其他样式(。

我在 CSS 中line 114放了一个类(这是来自 dataTables 的原始 css(,这使文本变大,

.sorting_1{
  font-size: 29px;
  line-height: 29px;
}

它不适用于其他列(因为我假设 .sorting_2.sorting_3(等(是更改它的类(。查看检查面板时,您可以看到更改单元格的<td>标签都具有sorting_1类,但其他单元格没有,我不确定该怎么做,

我该怎么做?

每行都有 evenodd 类,因此您可以使用 nth-of-type 指定要设置样式的td并从那里开始。 您必须同时设置偶数列和奇数列的样式,因此必须像这样指定两者:

.even td:nth-of-type(4), 
.odd td:nth-of-type(4){
  background:red;
}
.even td:nth-of-type(5), 
.odd td:nth-of-type(5){
  font-size:20px;
}

或者,您可以通过角色属性指定它并使用如下所示nth-of-type

tr[role=row] td:nth-of-type(4){
  background:red;
}
tr[role=row] td:nth-of-type(5){
  font-size:20px;
}

最新更新