css - 选择表中的第一个列表 - CSS first-child?

标签 css css-selectors

也许我找错人了。我有一个包含 6 列的表格,每个列中都有一个有序列表。我希望它们除了第一个列表外都具有边框。

The site is in development here基本上虽然 html 是

<tr>
 <td>
   <ol>
    <li>hello</li>
   </ol>
 </td>
 <td>
   <ol>
    <li>hello</li>
   </ol>
 </td>
 <td>
   <ol>
    <li>hello</li>
   </ol>
 </td>
</tr>

我以为 tr 的第一个 child 会这样工作 tr:first-child ol {style}

最佳答案

:first-child 选择器是 CSS2,在 IE6 上不受支持。如果 IE6 很重要,那么您需要为第一个 child 提供一个您可以选择的类(class)。但正确的语法是:

tr td:first-child ol { ... }

当你这样做时:

tr:first-child ...

您实际上选择了 <tr> 第一个 child 的元素。另请注意:

tr :first-child ...

正在选择第一个 表行的 child 。

关于css - 选择表中的第一个列表 - CSS first-child?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2197133/

相关文章:

CSS 导航对齐

javascript - 如何禁用 Bootstrap 样式

css - 类的第一个元素的CSS选择器

html - 为什么我的属性选择器在没有任何空格的情况下仍然有效?

css - 子选择器的替代品是什么?

html - CSS 选择器层次结构?如何通过逆向工程获得样式?

html - DIV 高度不是 100%

html - 在链接 anchor 后添加分隔线

html - 从表格单元格中删除空格

css - 我的网格数学辅助 : nth-child(an+b)