我有一个新闻文章网格,我想要它,所以网格中的最后两篇文章没有底部边框,但是我的 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/
发布评论
评论(2)
正如@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
。JSFiddle:http://jsfiddle.net/HJE5h/5/
As mentioned by @BoltClock above, swap the
broder-bottom
forborder-top
and target thefirst-child
instead. SOme older browsers do not supportlast-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 useborder-top
as suggested above and then target the nextselect
element that directly follows thefirst-child
, you can removeborder-top
from the first two articles.JSFiddle: http://jsfiddle.net/HJE5h/5/
您可以通过使用 nth-last-child(n) 伪类来实现这一点。它从集合的末尾开始,这样您就可以在不知道集合大小的情况下指定最后两个元素。请在您的 css 代码中尝试此选择器:
这是有用的 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:
This is a good reference for useful css selectors http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/