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

byr*_*gur 7 css article html5

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

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>
Run Code Online (Sandbox Code Playgroud)

CSS

.parent .example{ background-color: red;}
.parent .example:last-child{background-color: yellow;}
Run Code Online (Sandbox Code Playgroud)

jam*_*ase 14

last-child目标,以及父母的最后一个孩子.在这种情况下,最后一个子节点是section没有类的example,因此没有任何内容与选择器匹配.

你要找的是last-of-type,它匹配元素而不是类.看一看.