nth-child选择了错误的元素

对于这个特定的站点,当我通过CSS或jQuery使用nth-child时,’nth-child’选择器正在捕获错误的元素。 我在调用的选择器之前得到一个孩子:

.home article:nth-child(3) {} //captures 2nd child 

这似乎是捕获第二个孩子。 如果我尝试:

 .home article:nth-child(1) {} //captures nothing 

这没有捕获任何元素。 在jQuery中,它显示为一个空数组。 这是我正在开发的开发站点。 谢谢。

http://heilbrice.designliftoff.com/

在您的站点中,您有一个clearfix div ,它是容器中其父元素的第一个子元素,因此您的第一article实际上是第二个子文件,而不是第一个:

 

在CSS中,您可以使用:nth-of-type()代替到达第三篇article元素:

 /* Select the 3rd article in its parent within .home */ .home article:nth-of-type(3) {} 

奇怪的是, jQuery不支持:nth-of-type() ,因此对于跨浏览器解决方案,您必须选择:eq()其中包含从零开始的索引:

 // Select the 3rd article within .home $('.home article:eq(2)')