【发布时间】:2015-05-20 18:20:02
【问题描述】:
我发现这篇文章符合我的要求: Append Span Tag, after every 3rd div Jquery http://jsfiddle.net/pxaS4/2/
但我使用的是三列布局。我想澄清一下:每三个帖子之后,如果它们的高度不同,它们将始终保持 3 连续。
html:
<div class="post-listing">
<div class="post-item">
This text make the post-item different height.
</div>
<div class="post-item">
This text make the post-item different height. This text make the post-item different height.
</div>
<div class="post-item">
This text make the post-item different height.
</div>
<div class="post-item">
This text make the post-item different height. This text make the post-item different height. This text make the post-item different height.
</div>
<div class="post-item">
This text make the post-item different height.
</div>
<div class="post-item">
This text make the post-item different height. This text make the post-item different height.
</div>
<div class="post-item">
This text make the post-item different height. This text make the post-item different height. This text make the post-item different height.
</div>
<div class="post-item">
This text make the post-item different height.
</div>
<div class="post-item">
This text make the post-item different height.
</div>
</div>
CSS:
.clear {
clear: both;
color: #000;
}
.post-listing {
width: 300px;
}
.post-listing .post-item {
float: left;
color: red;
background: #ccc;
width: 32%;
margin-right: 2%;
margin-bottom: 30px;
}
.post-listing :nth-child(3n+0).post-item {
margin-right: 0%;
clear: right;
}
这似乎工作正常。问题是当我尝试在每三个帖子之后使用 jquery 添加一个 div 类“clear”时。这是我所拥有的,但它不起作用:
$('div.post-listing > div.post-item:nth-child(3n)').after('<div class="clear">this is the clear class</div>');
jsfiddle(非工作)在这里:jsfiddle
非常感谢任何帮助。 谢谢
【问题讨论】:
-
你的小提琴没有加载 jQuery。添加jQuery时似乎做你想做的事? jsfiddle.net/936qtbu5/2