2013-01-18 24 views
6

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

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;} 

回答

13

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

你在找什么是last-of-type,它匹配元素而不是类。 Take a look.

+0

“各篇的最后一个孩子”就是这样......不知道那...感谢 – byronyasgur

+0

抱怨..你知道任何它不与IE8的工作... JS以外的其他方式? – byronyasgur

+0

从头开始...最后一个孩子不会与IE8一起工作:-O – byronyasgur

0

,因为选择说

+0

它如何让它定位到最后一篇文章?即不是部分 – byronyasgur

相关问题