我正在尝试使用.latest-item
隐藏姓名为nth-child
的最后3个div:
<div class="latest-group">
<div class="latest-1 latest-item latest-sort-1">
<h3>Title</h3>
<p>Paragraph</p>
</div><!--end latest-1-->
<div class="latest-2 latest-item latest-sort-2">
<h3>Title</h3>
<p>Paragraph</p>
</div><!--end latest-2-->
<div class="latest-3 latest-item latest-sort-3">
<h3>Title</h3>
<p>Paragraph</p>
</div><!--end latest-3-->
</div><!--end latest-group-->
<div class="latest-group">
<div class="latest-4 latest-item latest-sort-1">
<h3>Title</h3>
<p>Paragraph</p>
</div><!--end latest-4-->
<div class="latest-5 latest-item latest-sort-2">
<h3>Title</h3>
<p>Paragraph</p>
</div><!--end latest-5-->
<div class="latest-6 latest-item latest-sort-3">
<h3>Title</h3>
<p>Paragraph</p>
</div><!--end latest-6-->
</div><!--end latest-group-->
和CSS:
.latest-item:nth-child(n+3) {
display:none;
}
我无法正确定位类名为.latest-item
的div。在jQuery中我可以做类似的事情:
$( “最新项目。”)片(3).hide();
这是一个小提琴:
答案 0 :(得分:2)
答案 1 :(得分:0)
听起来这是目前CSS的一个缺点。改为使用javascript:
$(".latest-item").slice(3).hide();