为什么最后一个孩子没有针对这个小提琴中的最后一篇文章标签?

时间:2013-01-18 21:32:40

标签: css html5 article

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

2 个答案:

答案 0 :(得分:14)

last-child目标,也就是父母的最后一个孩子。在这种情况下,最后一个孩子是section,它没有类example,因此没有任何东西与选择器匹配。

您要找的是last-of-type,它匹配元素而不是类。 Take a look.

答案 1 :(得分:0)

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

相关问题