2014-09-22 113 views
1

是否有一个CSS速记,我可以用这个规则排除表的第一列和第二列?CSS表列规则

th.header { 
     background-image: url(../static/images/bg.gif); 
     background-repeat: no-repeat; 
     background-position: right center; 
    } 

我认为我需要的列相当于:tr:not(.firstrow)

回答

4

如果有问题的单元没有跨越多个列(即没有0​​不是1),则可以使用:nth-child()

您可以逐一排除列:

th.header:not(:nth-child(1)):not(:nth-child(2)) { 
    background-image: url(../static/images/bg.gif); 
    background-repeat: no-repeat; 
    background-position: right center; 
} 

或者,如果列排除是连续的,你想,比如说,从第三个栏开始,使用:nth-child()用公式n+b其中b是你想开始的列:

th.header:nth-child(n+3) { 
    background-image: url(../static/images/bg.gif); 
    background-repeat: no-repeat; 
    background-position: right center; 
} 
+1

打算添加一个答案来覆盖':nth-​​child(n + 3)'选项,但是你的编辑击败了我。 – Albatros064 2014-09-22 18:24:48