CSS3 使用 :nth selectors 选择嵌套表格

标签 css css-selectors css-tables

<分区>


关闭 7 年前

我已经设置了标记。这是 link . 我无法弄清楚如何单独选择表格中的表格。我需要使用 :nth 选择器选择嵌套表的 trtd

最佳答案

根据您的标记,以下 CSS 应该可以满足您的需求。如果我正确阅读了你的问题,那就是......

table tr:nth-child(4) td:nth-child(1) table{background-color:#f0f;}
table tr:nth-child(4) td:nth-child(2) table{background-color:#0ff;}

这将选择包含两个内部表格的表格行,然后选择每个表格。

更好的方法当然是使用带有 ID/类名称的 div。表格应该用于表格数据,而不是布局。

你的 fiddle已更新

关于CSS3 使用 :nth selectors 选择嵌套表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32196808/

上一篇:html - "aria-describedby"和 "aria-hidden"属性如何在 Bootstrap 中工作?

下一篇:html - 如何使用绝对位置将页脚固定在底部?

相关文章:

css - 使 flex 父横轴适合元素

CSS 列在除 IE 和 Firefox 3 之外的所有地方都重叠

css - 带选择框的水平列表

html - 媒体查询在两个不同页面上的页脚有两个不同的结果,即使代码相同?

html - 即使在添加 btn 类后,bootstrap 提交按钮仍显示蓝色

python - Selenium CSS_Selector 寻找具有特定文本的元素结果是 'NoSuchElementException'

css - 在 css 中禁用@media

html - CSS even nth-child 嵌套 img 问题

html - 用 n 种颜色为表中的行着色

html - 如何垂直对齐表格单元格中的图像和文本?