2014-09-22 112 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