我想选择表的第三行,而不使用伪类或不将类应用于该行(更多的是练习兄弟运算符的工作原理)。
但它也适用于第四行及以下行。
tbody > tr + tr + tr {
color: blue;
}
<table>
<tbody>
<tr><td>Hello</td></tr>
<tr><td>World</td></tr>
<tr><td>Should be blue</td></tr>
<tr><td>Should not be blue</td></tr>
</tbody>
</table>
最佳答案
没有伪选择器?好吧,您可以在 tbody > tr + tr + tr + tr
上使用 color:initial
(您可以重置您在使用 initial
在此选择器中的第三个 tr
- 请参阅下面的演示:
tbody > tr + tr + tr {
color: blue; /* styles for the third row */
}
tbody > tr + tr + tr + tr{
color: initial; /* reset all the styles applied in the third row here */
}
<table>
<tbody>
<tr><td>Hello</td></tr>
<tr><td>World</td></tr>
<tr><td>Should be blue</td></tr>
<tr><td>Should not be blue</td></tr>
</tbody>
</table>
关于html - 如何在不使用类或伪类的情况下选择表行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55002038/