CSS - 仅在表格的 tbody 中选择第 th 个标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2454936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS - select th tags only within the tbody of a table
提问by Jeremy
I would like to use a css selector to get only the th tags with the tbody. There are also th tags in the thead section, which I don't want included by the selector. Here's the markup I'm working with. Is there a selector to accomplish this?
我想使用 css 选择器来仅获取带有 tbody 的 th 标签。在 thead 部分还有 th 标签,我不希望选择器包含它们。这是我正在使用的标记。有没有选择器来完成这个?
<table class="bgtable">
<thead><tr><td width="40%"> </td>
<th class="tdplain">Grade 4</th>
<th class="tdplain">Grade 8</th>
<th class="tdplain">Grade 12</th>
</tr>
</thead>
<tbody><tr><th class="tdplain">Civics (2010)</th>
<td class="tdplain">769K</td>
<td class="tdplain">577K</td>
<td class="tdplain">1179K</td>
</tr>
</tbody>
</table>
回答by jessegavin
.bgtable tbody th {
color: red;
}
回答by Matt Ball
table.bgtable tbody th {
/* CSS rules here */
}
回答by dirq
tbody>tr>th {color:red;}
回答by arthur
Although the previous are all valid, one can still be more precise (the css-selecting being not so performant).
虽然前面的都是有效的,但仍然可以更精确(css-selecting 不是那么高效)。
table.bgtable > tbody > th {
color:red;
}
if you got more than one table, which doesn't belong to the class, you don't want to include it to your selection that's why "table.bgtable".
如果您有多个不属于该类的表,您不想将其包含在您的选择中,这就是“table.bgtable”的原因。
kwoning to you can embeded th with other tag withitn the tbody you would be sure to find them otherwise like that: table.bgtable > tbody th
您可以在 tbody 中嵌入其他标签,否则您一定会找到它们: table.bgtable > tbody th