【发布时间】:2014-05-15 09:27:10
【问题描述】:
为什么:not(:last-of-type) 在以下情况下不起作用?我该如何解决?
JSFiddle:http://jsfiddle.net/C23g6/589/
HTML:
<div class="comment">This is Red</div>
<div class="hello">------------------</div>
<div class="comment">This is Red</div>
<div class="hello">------------------</div>
<div class="comment">Shouldn't be Red</div>
<div class="hello">------------------</div>
CSS:
.comment:not(:last-of-type) {
color: red;
}
【问题讨论】:
-
:last-of-type不适用于课程。它适用于元素类型。由于所有元素都是divs,所以显然不行。 -
在这种情况下我可以使用其他东西吗?
-
我自己找到了解决方案。我只是将 div 更改为类为
.comment的跨度,并在 CSS 中创建了.commentdisplay: block。 -
div:not(:nth-last-of-type(2)){color: red}
标签: css css-selectors