是否有可能在第一<tr>
第一<th>
應用規則,如果有2個或更多<thead>
<tr>
?CSS:適用於第一<tr><th>規則,如果有2 <tr>
我所做的:
table tr:first-child th:first-child
,但如果只有1 <tr>
TI反正申請。
是否有可能在第一<tr>
第一<th>
應用規則,如果有2個或更多<thead>
<tr>
?CSS:適用於第一<tr><th>規則,如果有2 <tr>
我所做的:
table tr:first-child th:first-child
,但如果只有1 <tr>
TI反正申請。
您可以使用:not()
和:only-child
選擇的組合,像這樣:
tr:first-child:not(:only-child) th:first-child {
color:red;
}
代碼比較自我解釋,它只會影響到第一個孩子,如果它不是唯一的孩子。
它具有相對較差support不過,你可能需要一個javascript polyfill來彌補,如果你需要支持IE8或以下。
我不認爲這是可能的,而不使用css class
。如果您正在動態創建tr。我建議如下操作:
if(condition for rows > 2) {
<tr><th class="applyCSS"></th><th></th></tr>
<tr><th></th><th></th></tr>
......
}
else { //only one tr
<tr><th></th><th></th></tr>
}
CSS:
applyCSS { .... }
如果你有一些默認的風格,你可以把它應用到'TR:獨生子女日:第一child'到只有孩子的情況下「覆蓋」。 – Passerby 2013-04-26 09:46:36