当表格标题的属性为commit="123“时,我想要更改整个表格行的颜色(使用CSS)。我试过了:
[commit="123"] {
color:#aaffff;
background-color:#111111;
}但是,这只会更改表头(1)。如何选择表头commit设置为"123“的整个表行(1项1)?谢谢!
[commit="123"] {
color: #aaffff;
background-color: #111111;
}<table class="code">
<tbody>
<tr>
<th id="1" commit="123">1</th>
<td>
<i>entry 1</i>
</td>
</tr>
<tr>
<th id="2" commit="456">2</th>
<td>
<i>entry 2</i>
</td>
</tr>
</tbody>
</table>
发布于 2020-03-07 01:17:29
为什么不直接将commit应用于表行而不是表头呢?不幸的是,CSS目前不支持父级的反向选择器。
[commit="123"] {
color: #aaffff;
background-color: #111111;
}<table class="code">
<tbody>
<tr id="1" commit="123">
<th>1</th>
<td>
<i>entry 1</i>
</td>
</tr>
<tr id="2" commit="456">
<th>2</th>
<td>
<i>entry 2</i>
</td>
</tr>
</tbody>
发布于 2020-03-07 01:18:48
您可以使用general sibling combinator (~)选择行中所有后面的td。
这不会样式化tr,没有可以随心所欲的CSS选择器,但是你可以用这种方式达到类似的效果。
[commit="123"],
[commit="123"]~td {
color: #aaffff;
background-color: #111111;
}<table class="code">
<tbody>
<tr>
<th id="1" commit="123">1</th>
<td>
<i>entry 1</i>
</td>
<td>
<i>entry 1.2</i>
</td>
</tr>
<tr>
<th id="2" commit="456">2</th>
<td>
<i>entry 2</i>
</td>
<td>
<i>entry 2.2</i>
</td>
</tr>
</table>
发布于 2020-03-07 01:20:03
不是将提交添加到表头(即),您需要将其写入以满足您的需求。
希望这能有所帮助。
https://stackoverflow.com/questions/60568660
复制相似问题