CSS 选择第一个 child

标签 css css-selectors

我仍在努力弄清楚如何正确使用我的 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-childlast-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/

相关文章:

javascript - iPhone safari Web 应用程序 float div

html - 用空间 build 等柱

css - 在一个规则中使用多个类的目标元素

python - 如何避免在网络爬行时出现断词

c# - 在html中创建树状结构的简单解决方案

javascript - 模态交叉按钮不适用于鼠标单击

html - 为什么 .classname > ul {color :red} make all nested <ul>s red?

jquery - 需要css转js实现

jQuery 或 CSS 选择器选择所有以某个字符串开头的 ID

html - 在 css 中添加新列并使其响应