对于这个特定的站点,当我通过 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/
在你的网站上,你有一个clearfixdiv
这是容器中其父元素的第一个子元素,因此您的第一个article
确实是second孩子,不是第一个:
<div class="row-main clearfix">
<div class="clearfix"></div> <!-- .row-main.clearfix > :nth-child(1) -->
<article id="post-" class=""> <!-- .row-main.clearfix > :nth-child(2) -->
在 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)')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)