I have a fluid grid (in height and width). The LIs are always rectangular and adapt them self’s to the screen size.
Now i need to fill the lists, so they all have the same height.
This would be easy if the all the columns had a with of one LI element.
But there are double sized columns and some of them can contain big sized LI’s. In some cases there is even empty spaces in the middle of the column, because there is a big Li a small one and just after it a big one again.
On some content pages all li’s are in a single column.
In every case the li’s are floated left. I have made some images to explain the problem:

First i wanted to count the child’s and compare them. But it got complicated when all LI’s are in a single column or when a LI’s is missing in the middle of the column.
This is what i have tried:
var longest = 0
$("ul.grid-col").each(function(){
var liCount, $that = $(this);
liCount = $that.find("> li").length;
if ($that.is(".double")){
if( $that.find("li.big").length ){
var bigCount = $that.find("li.big").length
liCount = (liCount - bigCount) + (bigCount * 4) //because one big has the size of 4 small one
}
liCount = liCount / 2
}
if ( longest < liCount ){
longest = liCount
}
})
Now i know how many LI’s i need to fill the empty spaces, its pretty easy to fill them up. But how do i find out if there is a empty space in the middle of the li’s? And how would you handle the special case of the single column?
I got this to work in FF. Hopefully I understood you question correctly. I tried to emulate your situation by building an html shell to work with. I’m not sure it matches your code, but I based in upon your image.
The gist of my approach is as follows:
The single column ul’s were pretty easy. Iterate over all of the ul’s to see what the max height is. Divide the maxHeight by the li height and add li’s to fill out as needed.
The double-wide ul’s were a bit trickier. I created a simple array to represent the single spaces that would make up the double wide columns. Then, I step through each li and update the status of the spaces index as filled where appropriate. If a double occurs where a single is needed, then I add a new li. After coming to the end of the li array for the double ul, i check the spaces array once more to make sure there aren’t any empties at the end of the ul.
Hopefully the code is a bit clearer than my explanation. 🙂