n-last-of-type不能在我的div上工作?

时间:2014-08-14 08:13:13

标签: html css css3 css-selectors

demo http://jsfiddle.net/5m38knq7/

我希望摆脱div的最后一个边界,但它不起作用?

.content-box .item div:nth-last-of-type(1) {
    border: none !important;
}

2 个答案:

答案 0 :(得分:2)

.content-box .item div:nth-last-of-type(1)将与div的后代.item匹配,而您应定位.item(因为您在.item上设置了边框)。所以它应该是:.content-box div.item:nth-last-of-type(1),但请注意,您的最后一个div包含Top链接,因此正确的规则为.content-box div.item:nth-last-of-type(2)

Updated demo

答案 1 :(得分:1)

你可以使用像这样的最后一个元素

p:last-of-type
{
background:#ff0000;
} 

:last-of-type选择器匹配其父元素的特定类型的最后一个子元素。

提示:这与:nth-​​last-of-type(1)相同。