我仍在努力弄清楚如何正确使用我的 nth
, first
, 和 last
子选择器。感谢您的耐心等待。
如果我的标记是这样的:
<div class="the-wrapper">
<table class="the-table">
<!-- the table -->
</table>
<table class="the-table">
<!-- the table -->
</table>
</div>
如何选择最后一个 <table class="the-table">
申请 margin ?
我想我可以这样选择它:.the-wrapper .the-table:last-child { /* css */ }
但这不起作用。我错过了什么?谢谢!
编辑
对不起大家,我打印的标记不正确...正确的标记在上面
最佳答案
+
用于选择“兄弟”元素。 (同父异母的 sibling )http://jsfiddle.net/Lhmjq/
您不能为此使用nth-child
或last-child
;顾名思义,是给 childs
的,除非你放一个 parent ,否则你做不到。
这是一个有 parent 的例子:http://jsfiddle.net/Lhmjq/2/在这种情况下,使用 last-child
(已更新为您的新代码) 这是一个小标题:http://jsfiddle.net/Lhmjq/4/
.the-wrapper .the-table:last-child {
color: blue;
}
更新了您的新代码:http://jsfiddle.net/Lhmjq/4/
关于CSS 选择第一个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18319746/