为什么last-child不针对最后一篇文章标签?
http://jsfiddle.net/gunP9/<div class="parent">
<article class="example">111</article>
<article class="example">111</article>
<article class="example">111</article>
<article class="example">111</article>
<section>content</section>
</div>
CSS .parent .example{ background-color: red;}
.parent .example:last-child{background-color: yellow;}
last-child
的目标是父元素的最后一个子元素。在本例中,最后一个子元素是没有类example
的section
,因此没有任何元素与选择器匹配。
您正在寻找的是last-of-type
,它匹配元素而不是类。
因为选择器显示"last child of each of articles"