Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS-仅在表体中选择th标记_Css_Css Selectors - Fatal编程技术网

CSS-仅在表体中选择th标记

CSS-仅在表体中选择th标记,css,css-selectors,Css,Css Selectors,我想使用css选择器只获取带有tbody的th标记。THAD部分中还有th标记,我不希望选择器包含它。这是我正在使用的标记。是否有一个选择器来实现这一点 <table class="bgtable"> <thead><tr><td width="40%">&nbsp;</td> <th class="tdplain">Grade 4</th> <th class="tdplain">Grade

我想使用css选择器只获取带有tbody的th标记。THAD部分中还有th标记,我不希望选择器包含它。这是我正在使用的标记。是否有一个选择器来实现这一点

<table class="bgtable">
<thead><tr><td width="40%">&nbsp;</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>

四年级
八年级
十二年级
公民(2010)
769K
577K
1179K

虽然前面的都是有效的,但仍然可以更精确(css选择的性能不太好)

如果您有多个不属于该类的表,则不希望将其包括在您的选择中,这就是“table.bgtable”的原因


kwoning to you可以将th与其他标记一起嵌入到tbody中,您肯定会发现它们是这样的:
table.bgtable>tbody th

我不认为这是真的。我支持乔尔的评论。我找不到任何说明在
TBODY
中不能有
TH
的规范。W3C验证器今天早上有点慢。我终于让它加载并运行了一个测试-你们是对的!出于好奇,为什么投了反对票?我的答案实际上与公认的答案相同。我不介意被否决,但我很欣赏你的评论。+1:这是正确的,但如果你能帮助的话,请不要使用元素类型选择器,也就是说,如果
,不要使用
table.bgtable
if
。bgtable
有效。
.bgtable tbody th {
   color: red;
}
table.bgtable tbody th {
 /* CSS rules here */
}
tbody>tr>th {color:red;}
table.bgtable > tbody > th {
color:red;
}