7

为什么 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;}
4

2 回答 2

14

last-child目标,嗯,父母的最后一个孩子。在这种情况下,最后一个孩子是 a section,它没有 class example,因此没有任何内容与选择器匹配。

您正在寻找的是last-of-type,它匹配元素而不是类。看一看。

于 2013-01-18T21:33:45.257 回答
0

因为选择器说“每篇文章的最后一个孩子”

于 2013-01-18T21:34:24.090 回答