html - 所有特定的 CSS 选择器
问题描述
我有多个这样的表
表格1
<table border="1" style="border-collapse: collapse">
<thead>
<tr>
<th class="One">One</th>
<th class="Two">Two</th>
<th class="Three">Three</th>
</tr>
</thead>
<tbody>
<tr>
<td>DateTime</td>
<td>Price</td>
<td>Number</td>
</tr>
<tr>
<td>DateTime</td>
<td>Price</td>
<td>Number</td>
</tr>
</tbody>
</table>
表 2
<table border="1" style="border-collapse: collapse">
<thead>
<tr>
<th class="Two">Two</th>
<th class="Three">Three</th>
<th class="One">One</th>
<th class="Four">Four</th>
</tr>
</thead>
<tbody>
<tr>
<td>Price</td>
<td>Number</td>
<td>DateTime</td>
<td>Text</td>
</tr>
<tr>
<td>Price</td>
<td>Number</td>
<td>DateTime</td>
<td>Text</td>
</tr>
</tbody>
</table>
表共享一些列,但它们可以按不同的顺序排列。可以只为我的班级设置特定列的样式吗?例如,将颜色设置为红色,对于所有具有“三”类的<td>
位置。<th>
解决方案
干得好。由于您想针对特定列,从您在示例中的表中,我想如果您能够定位a 的每一nth-child(2)
列,那么您很好,您的 CSS 代码应该如下所示。td
tr
tr.redClass td {
background-color: #a33;
color: #fff;
}
.redCol td {
background-color: #a33;
color: #fff;
}
.every-other-one tr:nth-child(n) td:nth-child(2) {background: #a33}
<!-- set classes for all tr -->
<p> A class for spesial col</p>
<table border="1" style="border-collapse: collapse" class="every-other-one">
<thead>
<tr>
<th class="Two">Two</th>
<th class="Three">Three</th>
<th class="One">One</th>
<th class="Four">Four</th>
</tr>
</thead>
<tbody>
<tr>
<td>Price</td>
<td>Number</td>
<td>DateTime</td>
<td>Text</td>
</tr>
<tr>
<td>Price</td>
<td>Number</td>
<td>DateTime</td>
<td>Text</td>
</tr>
<tr>
<td>Price</td>
<td>Number</td>
<td>DateTime</td>
<td>Text</td>
</tr>
</tbody>
</table>
<br>
我希望可以为您服务。干杯
推荐阅读
- python - 使用启用了 2 因素身份验证的 python 脚本从 nextcloud 下载文件
- spring - 如何使用 spring cloud config server 和 spring cloud bus 和 rabbit mq 更新配置?
- javascript - 如何在 Shopify 上默认选择输入列表的第一个单选按钮选项?
- r - 过滤数据框以保留行,直到列值更改为 0
- ruby-on-rails - ActiveRecord::RecordInvalid:验证失败:用户必须存在
- apache - htaccess:重定向到 https://subdomain.domain.com
- node.js - 具有一个 Redis 实例和多个服务器角色的 Cron 集群
- mysql - MySQL为每一行加入外部表中的最新行
- angular - Angular - 异步响应式表单验证器的问题
- linux - 在 Virtualbox 中安装后缺少 Linux-OS