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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2197133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 21:31:06  来源:igfitidea点击:

Select first list in table - CSS first-child?

csscss-selectors

提问by morktron

maybe I'm barking up the wrong tree. I'm have a table with 6 columns, each with an ordered list in. I want them all to have a border except for the first list.

也许我吠错了树。我有一个有 6 列的表,每列都有一个有序列表。我希望它们都有一个边框,除了第一个列表。

The site is in development hereBasically though the html is

该网站正在开发中基本上虽然 html 是

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

I thought the first-child of tr would work like so tr:first-child ol {style}

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

回答by cletus

The :first-childselector is CSS2 and isn't supported on IE6. If IE6 is important then you'll need to give the first child a class you can select on instead. But the correct syntax is:

:first-child选择器是CSS2和不支持IE6。如果 IE6 很重要,那么你需要给第一个孩子一个你可以选择的类。但正确的语法是:

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

When you do:

当你这样做时:

tr:first-child ...

you're actually selecting <tr>elements that arefirst children. Also be aware that:

你实际上选择<tr>的元素第一个孩子。另请注意:

tr :first-child ...

is selecting the first children oftable rows.

是选择第一个孩子表行。

回答by ЯegDwight

That's not quite how it works, tr:first-child olselects the trthat is the first child of its parent element. You must use the first-childpseudoclass on the tdinstead.

这不是它的工作原理,tr:first-child ol选择作为其父元素的第一个子元素的tr。您必须在first-child上使用伪类td