2013-08-21 24 views
0

我有一個簡單的表:自第一胎在引導3.0

​​

通過自定義CSS:

tr:first-child { 
    color: #696969; 
    background-color: black; !important; 
} 

的色彩應用,但background-color,是不是。爲什麼?用last-childbackground-color工作。謝謝。

更新:如果我刪除table-striped它的作品。但我需要保持它。

UPDATE2:table-striped引導CSS:

.table-striped > tbody > tr:nth-child(odd) > td, 
.table-striped > tbody > tr:nth-child(odd) > th { 
    background-color: #f9f9f9; 
} 

回答

1

發現它,它的選擇器問題, 選擇器B3使用更具體,現在,把你的CSS作爲順序如下。 例子:

<link rel="stylesheet" href="css/bootstrap.css"> 
<link rel="stylesheet" href="css/custom.css"> 

,並在custom.css

.table-striped > tbody > tr:first-child > td, 
.table-striped > tbody > tr:first-child > th { 
    color: #696969; 
    background-color:#000; 
} 

我測試過,結果添加這個CSS是你所需要的。 http://jsfiddle.net/TAp7T/1/

+0

我的順序是css。我的方式或你的方式只適用於IE。在FF和Chrome上不起作用。謝謝。 – Khrys

+0

不知道如何通知工作,但這裏告訴你,我剛剛更新它 – Kooki3

+0

是啊,作品!謝謝。 – Khrys

1

變化

background-color: black; !important; 

background-color: black !important; 
+0

不起作用... – Khrys

0

只是選擇添加更多的類或ID來你不需要很重要讓它像這樣工作並將你的風格應用於td

table.table-condensed.table.table-striped tr:first-child td{ 
    color: #696969; 
    background-color: black; 
} 

小提琴here

+0

剛更新了帖子。 Bootstrap中有一些關於「表格條帶化」的內容。在一個'正常'的CSS世界中......它應該起作用。 – Khrys

+0

我認爲這是行不通的,因爲你在那裏添加了一個不在html中的tbody – amdorra

0

無論!important,CSS樣式被應用到first-childlast-child。請參閱JSFiddle firstfirst-childJSFiddle lastlast-child。可能你只顯示了你的項目的一部分,所以我們只能根據你提供的信息進行分析。該代碼確實將background-color應用於任何孩子。

+0

剛剛更新了帖子。 Bootstrap中有一些關於「表格條帶化」的內容。在一個'正常'的CSS世界中......它應該起作用。 – Khrys