从N开始的颜色表列(td:nth-​​of-type)

Alv*_*aro 3 html css css-selectors css-tables

我想从某一列开始添加某种背景颜色.而不是必须为每列使用css类,我宁愿在可能的情况下这样做.

我将有一个包含数百行和大约25列的大表,我更喜欢避免不必要的代码.

目前,我正在使用td:nth-of-type财产来做到这一点:

.demo tr.selectedRow td:nth-of-type(9),
.demo tr.selectedRow td:nth-of-type(10),
.demo tr.selectedRow td:nth-of-type(11),
.demo tr.selectedRow td:nth-of-type(12),
.demo tr.selectedRow td:nth-of-type(13),
.demo tr.selectedRow td:nth-of-type(14),
.demo tr.selectedRow td:nth-of-type(15),
.demo tr.selectedRow td:nth-of-type(16) {
  background-color: #fff16b;
}
Run Code Online (Sandbox Code Playgroud)

我想知道是否有任何方法可以减少这一点.

文档没有多说......

2ne*_*2ne 8

http://css-tricks.com/examples/nth-child-tester/这个测试人员可以提供帮助.看起来您想在9之后选择所有内容,因此请使用下面的代码

选择除First 8之外的每个TD

.demo tr.selectedRow td:nth-child(n+9) {
  color: red;
}
Run Code Online (Sandbox Code Playgroud)