i have a parent div that contains some random pictures that is in child divs about 7 or more. my aim is to have the parent div expand when the child divs populate it at random. note child divs can be 0 to 10 or more. the problem im having is that the parent div does not grow. i try using css and jquery and this is what i have so far jquery
var margin = 5;
var blocks = [];
function align() {
$( .block ).each(function(i){
var min = Array.min(blocks);
var index = $.inArray(min, blocks);
var posleft = margin+(index*(300+margin));
$(this).css({
left :(posleft+2)+ px ,
top :min+ px
});
blocks[index] = min+$(this).outerHeight()+margin;
});
}
function divlayOut() {
blocks = [];
for(var i=0;i<3;i++)
{
blocks.push(margin);
}
align();
}
Array.min = function(array) {
return Math.min.apply(Math, array);
};
html( html)
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<style type="text/css">
.block{
width: 250px;
float:left;
position:absolute;
}
.parent{
width: 800px;
float:left;
padding:10px 0px 0px 10px;
position:relative;
}
</style>
</head>
<body onload="align();">
<div class="parent">
<div class="block">pic1 size H 100 x W 80</div>
<div class="block">pic1 size H 80 x W 800</div>
<div class="block">pic1 size H 300 x W 100</div>
<div class="block">pic1 size H 110 x W 90</div>
</div>
希望下面的画面能帮助澄清我的目标
""https://i.sstatic.net/SBQ5X.png" alt="此处的内置图像描述"/ >