Bit of a puzzle for you....
I have a 730px wide, auto height div. Inside this I have will number of smaller divs 164px X 261px.
These will be pulled in to the template dynamically so I could have 1, or I could have 18 or for the sake of this excercise, I could have 1000 or anywhere in between.
I need to space these out so that on each line there is an equal distance between each. Simple if we are dealing with up to 4, I could do something like:
var totalWidth = $('.bigDiv .smallerDivs').length * $('.bigDiv .smallerDivs').width();
var margin = ($('.bigDiv').width - totalWidth) / ($('.bigDiv .smallerDivs').length * 2);
$('.bigDiv .smallerDivs').css('margin-left': margin , 'margin-right': margin);
However, when there are say 5. I want to have 3 on the top row and 2 on the bottom. Or if I have 7, I would like 4 on top 3 on bottom. If there are 11 I would like 4 on top, 4 in the middle and 3 below etc etc etc, each row nicely justified based on however many small boxes there are.
Can anyone suggest a nice clean way I may go about this?