![](/img/trans.png)
[英]How to get 1st,2nd,3rd,4th,5th child element of a specific <div id=“target”> with jQuery?
[英]jQuery + CSS - where 4th div is coming under 3rd div, wrap 3 div in one line, and 4th - on next line
我有一个ASP.Net-MVC视图,如果数据可用于该部分,则动态添加div
。 要求是单个线路应该容纳3个div
。
看看这个http://jsfiddle.net/tKKDY/4/
我有这个CSS
.section {
border: 1px solid Red;
width: 150px;
float: left;
}
和html这样
<div class='section'>hello</div>
<div class='section'>
hello hello hello hello hello hello hello hello hello hello hello
</div>
<div class='section'>hello</div>
<div class='section'>fourth hello</div>
<div class='section'>hello</div>
问题是,文本内容不是固定长度。 因此,第四个div
取代了第三个div
。 要解决这个问题,我可以拥有这样的CSS
类。
.row {
width: 100%;
float: left;
}
使用这个,我必须将parentDiv1
的内容parentDiv1
如parentDiv2
中所述。 我怎样才能使用jQuery
实现这一目标?
作为替代方法,在你的部分使用display: inline-block
而不是float: left
,你不需要.row
:
.section {
border: 1px solid Red;
width: 150px;
display: inline-block;
vertical-align: top;
}
更新了JSFiddle: http : //jsfiddle.net/tKKDY/5/
这个jQuery做到了......
$('#parentDiv1').filter(':visible').find(':lt(3)').wrapAll('<div class="row">');
得到前3个div
并用新div
包裹它,所以......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.