css最后一个孩子不工作

发布于 2024-12-22 10:22:48 字数 251 浏览 0 评论 0 原文

我有一个新闻文章网格,我想要它,所以网格中的最后两篇文章没有底部边框,但是我的 css last-child 选择器似乎不起作用,最后一篇文章右类的边框被取消,但是左类的最后一篇文章没有,这是有原因的吗?

这是我的代码和问题的小提琴。

http://jsfiddle.net/Udders/HJE5h/

I have a grid of news articles and I wanting it so the last two articles in the grid do not have a bottom border, however my css last-child selector does not seem to be working, the last article with the class right has the border taken off, however the last article with the class left does not, is there a reason for this?

Here is a fiddle of my code and problem.

http://jsfiddle.net/Udders/HJE5h/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬﹪忆之殇 2024-12-29 10:22:48

正如@BoltClock 上面提到的,将 broder-bottom 替换为 border-top 并以 first-child 为目标。某些较旧的浏览器不支持 last-child

JSFiddle:http:// jsfiddle.net/HJE5h/2/

编辑

好的,正如 @BoltClock 在下面的评论中提到的,问题并不完全在于 last-child 问题。但是,如果您确实按照上面的建议使用 border-top,然后定位紧随 first-child 的下一个 select 元素,您可以从前两篇文章中删除 border-top

section:first-child .snippet, section:first-child + section .snippet {
    background:none;
    border-top:none;
}

JSFiddle:http://jsfiddle.net/HJE5h/5/

As mentioned by @BoltClock above, swap the broder-bottom for border-top and target the first-child instead. SOme older browsers do not support last-child:

JSFiddle: http://jsfiddle.net/HJE5h/2/

Edit

Ok, as @BoltClock mentions in the comment below, the problem is not entirely with the last-child issue. However, if you do use border-top as suggested above and then target the next select element that directly follows the first-child, you can remove border-top from the first two articles.

section:first-child .snippet, section:first-child + section .snippet {
    background:none;
    border-top:none;
}

JSFiddle: http://jsfiddle.net/HJE5h/5/

屌丝范 2024-12-29 10:22:48

您可以通过使用 nth-last-child(n) 伪类来实现这一点。它从集合的末尾开始,这样您就可以在不知道集合大小的情况下指定最后两个元素。请在您的 css 代码中尝试此选择器:

.grid_9:nth-last-child(1) .snippet, .grid_9:nth-last-child(2) .snippet {
    background: none;
    border-bottom: none;
}

这是有用的 css 选择器的一个很好的参考 http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/

You can achieve that by using nth-last-child(n) pseudo class. It begins at the end of the collection and this way you can specify the last two elements without knowing the size of the collection. Please try this selector in your css code:

.grid_9:nth-last-child(1) .snippet, .grid_9:nth-last-child(2) .snippet {
    background: none;
    border-bottom: none;
}

This is a good reference for useful css selectors http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文