Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1095615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:09:13+00:00 2026-05-17T00:09:13+00:00

I have a fluid grid (in height and width). The LIs are always rectangular

  • 0

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:

grid problem grid problem2

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:09:14+00:00Added an answer on May 17, 2026 at 12:09 am

    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. 🙂

        <style type="text/css">*               {margin:0; padding:0; list-style:none; border:none; outline:none;}
    
        body            {}
    
        ul              {float:left; display:inline; background:#efefef; position:relative;}
        ul.single       {width:50px;}
        ul.double       {width:100px;}
        li              {float:left; display:inline; background:#dddddd; -moz-border-radius:10px;}
        li.single       {height:50px; width:50px;}
        li.double       {height:100px; width:100px; background:#999999;}
    
        .added          {background:#990000 !important;}
    </style>
    
    <script type="text/javascript">
        $(document).ready(function(){
            var maxHeight = 0;
            var maxWidth = 0;
    
            // Update the ul to manually set height and widths.
            $('ul').each(function(){
                var height = $(this).outerHeight();
                var width = $(this).outerWidth();
    
                $(this).css({
                    'height': height,
                    'width': width
                });
    
                if(height > maxHeight) {maxHeight = height;}
                if(width > maxWidth){maxWidth = width;}
            });
    
            var single = 50;
            var double = 100;
    
            // go over the li's and see if any spaces are empty.
            $('ul').each(function(){
                if($(this).hasClass('single')){
                    var totalSpaces = maxHeight / single;
                    var liCount = $(this).find('li').length;
    
                    for(var i = liCount; i<totalSpaces; i++){
                        $(this).append('<li class="single added">&nbsp;</li>');
                    }
                } else {
                    // Abstract a two column grid.
                    var totalSpaces = maxHeight / single * 2;
    
                    // Set up an array representation of the spaces.
                    var spaces = [];
    
                    // Preset all spaces as empty.
                    for(var i=0; i<totalSpaces; i++){
                        spaces.push(false);
                    }
    
                   var currentSpace = 0;
    
                    // Iterate over the li's and update spaces array.
                    $(this).find('li').each(function(index, ele){
                        if($(ele).hasClass('single')){
                            spaces[currentSpace] = true;
                            currentSpace++;
                        } else {
                            // Is this the right column?  (is the currentSpace odd?)
                            if(currentSpace % 2 != 0){
                                // Insert a single li.
                                $(ele).before('<li class="single added">&nbsp;</li>');
                                spaces[currentSpace] = true;
                                currentSpace++;
                            }
                            for(var i=currentSpace; i<(currentSpace + 4); i++){
                                spaces[i] = true;
                            }
                            currentSpace+=4;
                        }
                    });
    
                    // finally, go back over the spaces array and fill in any missing li's from the end.
                    var me = $(this);
                    $(spaces).each(function(index, ele){
                        if(!ele){
                            // insert a single li at the end.
                            $(me).append('<li class="single added">&nbsp;</li>');
                            spaces[index] = true;
                        }
                    });
                }
            });
        });
    </script>
    
    <ul class="single">
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
    </ul>
    
    <ul class="single">
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
    </ul>
    
    <ul class="double">
        <li class="double">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="double">&nbsp;</li>
        <li class="single">&nbsp;</li>
    </ul>
    
    <ul class="single">
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
    </ul>
    
    <ul class="single">
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
    </ul>
    
    <ul class="double">
        <li class="single">&nbsp;</li>
        <li class="double">&nbsp;</li>
        <li class="double">&nbsp;</li>
        <li class="single">&nbsp;</li>
    </ul>
    
    <ul class="single">
        <li class="single">&nbsp;</li>
        <li class="single">&nbsp;</li>
    </ul>
    
    <ul class="double">
        <li class="single">&nbsp;</li>
    </ul>
    
    <ul class="double">
        <li class="double">&nbsp;</li>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fluid grid layout, 3 rows, each with 3 different % width
I'm working on a fluid layout project. I have some fixed height DIVs in
I have a fluid grid built with <li> elements. eg: <ul> <li></li> <li></li> <li></li>
I have a fluid-width div with rounded corners using the border-radius, as well as
I have a fluid page (100% width) with this inside: [image-fixed-width] | [text-fluid-width -----------------------------------]
I am using Twitter Bootstrap and at one place I have nested fluid-grid in
I have a fluid width theme and I am using jQuery Masonry and Infinite
I have a fluid layout and I have a div that matches the height
The site should have a fluid-layout, adjusting to the width of the device, in
I don't actually need it now, but just out of curiosity... Suppose we have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.