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

  • SEARCH
  • Home
  • 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 9248003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:52:16+00:00 2026-06-18T09:52:16+00:00

I have an ul with fixed width 235px and height 200px. This ul is

  • 0

I have an ul with fixed width 235px and height 200px. This ul is populated by n numbers of li depending on a query results. How can I calculate the dimensions of the li in order for them to fill all the available space inside the ul.

I have tried calculating the container’s perimeter and comparing it with the total of each element’s perimeter but that doesn’t work.

  • 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-06-18T09:52:17+00:00Added an answer on June 18, 2026 at 9:52 am

    OK, here’s my attempt at code that will work out a fairly high coverage of the ul (not sure if it’s actually maximal), given the constraints that the lis need not be square, but must all be the same size for any given number of items.

    The first part gives a function getSquare(n) which will memoize the generation of squares, so that if you need to use it multiple times on a page it won’t keep recalculating things.

    The second part is the function that does the calculation. Pass it the number of items, and the width and height of your container, and it will return an object with width and height properties for the items. It doesn’t ensure integer results.

    The line with the throw is just there for testing purposes really, could be removed.

    var getSquare = (function()
    {
        var squares = [];
        return function(n)
        {
            if (!squares[n])
            {
                squares[n] = Math.pow(n, 2);
            }
            return squares[n];
        };
    })();
    
    
    function calcItemDimensions(itemCount, areaWidth, areaHeight)
    {
        var x, y, slots,
            n = 0,
            sq = 0;
    
        while (itemCount > sq)
        {
            n += 1;
            sq = getSquare(n);
        }
    
        x = y = n;
        slots = sq;
    
        while (slots - itemCount >= x)
        {
            if (x === y) { y -= 1; }
            else { x = y; }
            slots = x * y;
            if (slots < itemCount) { throw new Error('slots < itemCount: ' + slots + ' < ' + itemCount); }
        }
    
        return { width: areaWidth / x, height: areaHeight / y };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a container DIV with a fixed height and width (275x1000px). In this
I have this fixed-width file with the widths being 34, 2, 3, 2, 1,
I'm trying to have a fixed width sidebar with a 100% height, next to
I have an HTML textarea that is of fixed width, but variable height. I
I have a <div> with a fixed width and height floated left, and to
I have a (fixed-width and height) label which sums up a long list of
I have three fixed width integer types: typedef int16_t TABCellManagedDataKey; typedef int16_t TABCellManagedDataIndex; typedef
I want to have a fixed-width TextBlock that has long, unbroken, horizontal text, and
My code contains a table that I need to have a fixed width. The
I've created a series of tabs that have a fixed width of 100px. A

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.