css:如果有2个<tr>,则在第一个<tr> <th>上应用规则

Ato*_*ico 5 css

是否有可能在第一应用规则<th>第一的<tr>,如果有2个或更多<tr><thead>

我做了:

table tr:first-child th:first-child 
Run Code Online (Sandbox Code Playgroud)

但如果只有1 <tr>ti应用.

And*_*ndy 7

您可以使用:not():only-child选择器的组合,如下所示:

tr:first-child:not(:only-child) th:first-child {
    color:red;
}
Run Code Online (Sandbox Code Playgroud)

代码是相对自我解释的,它只会影响第一个孩子,如果它不是唯一的孩子.

DEMO

它有相对不好的支持,如果你需要支持IE8或更低版本,你可能需要一个javascript polyfill来弥补它.