html - 应用:不在嵌套表中
问题描述
table.parent td:nth-of-type(1):not(table.nested td){
color: red;
}
<table class="table parent">
<tbody>
<tr>
<td>TEXTA</td>
<td>TEXTB</td>
</tr>
<tr>
<td>Has nested table below
<table class="table nested">
<tbody>
<thead>
<th>S.No.</th>
<th>Name</th>
<th>Contact</th>
</thead>
<tr>
<td>1</td>
<td>ABC</td>
<td>PQR</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>TEXTC</td>
<td>TEXTD</td>
</tr>
</tbody>
</table>
我有一个嵌套表如下 -
<table class="table parent">
<tbody>
<tr>
<td>TEXTA</td>
<td>TEXTB</td>
</tr>
<tr>
<td>Has nested table below
<table class="table nested">
<tbody>
<thead>
<th>S.No.</th>
<th>Name</th>
<th>Contact</th>
</thead>
<tr>
<td>1</td>
<td>ABC</td>
<td>PQR</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>TEXTC</td>
<td>TEXTD</td>
</tr>
</tbody>
</table>
要求 - 只有 TEXTA 和 TEXTB 应该涂成红色。在实际场景中有很多行。我只希望父表中每一行的第一个 td 被着色。我正在做类似的事情 -
table.parent td:nth-of-type(1):not(table.nested td){
color: red;
}
这没有给我任何结果。实现这一目标的正确方法是什么?
解决方案
花了一段时间玩这个。我能做的最好的事情是建议使用 2 行 CSS 而不是 1 行。一个选择器完成所有第一行,一个选择器将它们td
设置nested
回它们所属的位置。
table.parent tr:first-child td {
color: red;
}
table.nested tr:first-child td {
color: black;
}
<table class="table parent">
<tbody>
<tr>
<td>TEXTA</td>
<td>TEXTB</td>
</tr>
<tr>
<td>Has nested table below
<table class="table nested">
<tbody>
<thead>
<th>S.No.</th>
<th>Name</th>
<th>Contact</th>
</thead>
<tr>
<td>1</td>
<td>ABC</td>
<td>PQR</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>TEXTC</td>
<td>TEXTD</td>
</tr>
</tbody>
</table>
推荐阅读
- calculation - 如何在不使用汇总汇总的情况下计算 PDF 报告模板中的总计
- java - @query Java JPA 中缺少双亲
- linux - 向 XHTML 内容添加标题部分和结束标记
- algorithm - 从一组点中找到最大矩形的高效算法
- reactjs - 导航到新页面时,BottomNavigation 不更新
- git - 在哪些情况下,pullrequest 的合并提交可能与 pullrequest 本身中显示的更改不同?
- c# - 当文本是某事时,那就这样做 - Unity 2D
- python - 如何在 Python 中使用面板数据对分数 logit 进行建模?
- vb.net - 重命名文件时出现“找不到部分路径”错误
- r - 在 R 中命名集群