大佬教程收集整理的这篇文章主要介绍了jquery – 从上到下对齐div,然后从左到右对齐,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
|---------------| | | | | 1 | 4 | |-------|-------| | | | | 2 | 5 | |-------|-------| | | | | 3 | 6 | |-------|-------|
我试过这些CSS,但它不起作用.
.SubDiv { height: 50px; width: 50px; BACkground: red; } .MainDiv { max-height: 200px; height: 200px; width: 200px; BACkground: blue; min-width: 100px; direction: inherit; } <div> <div id="SimulationPage"> <div id = "ParentDiv" class="MainDiv"> </div> </div> <input type='button' id = "adddiv" value='add div' /> </div> $(document).ready(function () { $('#adddiv').bind('click',function (eventargs) { $("#ParentDiv").append('<div class="SubDiv"> </div>'); }); });
有人可以帮我实现我想要的.
如果jQuery让你高兴(因为你已经在其中标记了这个问题)
here is a solution for dynamic count with jQuery
使用jQuery:
var count = $(".MainDiv").children().length; /*get @R_51_10586@l childs */ var mid_child = Math.ceil(count / 2) + 1; /* find mid child */ var x = 1; /*parameter to set negtaive margin,to push right float on toP*/ var current_div_number = mid_child; /* div number to set margin */ /*assign class name to 2nd half childs,to float them right through css,can be done through jQuery too!!*/ $(".MainDiv .SubDiv:nth-child(n+" + mid_child + ")").addClass("mid"); /* check each .mid class and assign negative margin-toP*/ $(".MainDiv .mid").each(function (indeX) { $(".MainDiv .SubDiv:nth-child(" + current_div_number + ")").css('margin-top',-(mid_child * 50) + (50 * X) + 'px'); x = x + 1; current_div_number = current_div_number + 1; });
CSS
.MainDiv > div.mid { float:right; BACkground: green; }
以上是大佬教程为你收集整理的jquery – 从上到下对齐div,然后从左到右对齐全部内容,希望文章能够帮你解决jquery – 从上到下对齐div,然后从左到右对齐所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。