选择表中的第一个列表 - 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
Select first list in table - CSS first-child?
提问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-child
selector 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 ol
selects the trthat is the first child of its parent element. You must use the first-child
pseudoclass on the td
instead.
这不是它的工作原理,tr:first-child ol
选择作为其父元素的第一个子元素的tr。您必须在first-child
上使用伪类td
。