仅在父 table 的第一个 tr 上应用 css 属性(仅使用 css 类,不使用 id)
Apply css properties on only first tr of parent table (using only css classes, no usage of id's)
<table>
<thead>
</thead>
<tbody class="someclass">
<tr>
<td>
</td>
<td>
<table>
<tbody>
<tr>
<td>.....</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
上面的代码片段我想用一些类来设置父 table 的第一个 tr 的样式:
.someclass tr td{
.......
......
}
但它也被应用于内部 table。
您可以使用以下 css
.someclass > tr {
// your css here
}
或
.someclass > tr:first-child {
// your css here
}
或
.someclass tr:first-of-type {
// your css here
}
我喜欢 Gosi 关于将 'first-of-type' 应用于您的 css 的回答。但后来我阅读了评论并意识到,所以我想我会跟进这个:
尝试:
.someclass tr:first-of-type {
background: blue;
}
根据 Gosi 的回答,再补充一下:
.someclass tr table tr:first-of-type {
background: none;
}
<table>
<thead>
</thead>
<tbody class="someclass">
<tr>
<td>
</td>
<td>
<table>
<tbody>
<tr>
<td>.....</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
上面的代码片段我想用一些类来设置父 table 的第一个 tr 的样式:
.someclass tr td{
.......
......
}
但它也被应用于内部 table。
您可以使用以下 css
.someclass > tr {
// your css here
}
或
.someclass > tr:first-child {
// your css here
}
或
.someclass tr:first-of-type {
// your css here
}
我喜欢 Gosi 关于将 'first-of-type' 应用于您的 css 的回答。但后来我阅读了评论并意识到,所以我想我会跟进这个:
尝试:
.someclass tr:first-of-type {
background: blue;
}
根据 Gosi 的回答,再补充一下:
.someclass tr table tr:first-of-type {
background: none;
}