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 9217745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:42:05+00:00 2026-06-18T02:42:05+00:00

I’m trying to fix a positing issue in a responsive design. I have a

  • 0

I’m trying to fix a positing issue in a responsive design.

I have a container div, containing 4 (but it could be more or less) divs that are displayed as inline-block. I would like to know how to control the number of divs per line when the page is resized (with CSS, if it’s possible). For example, when 4 containees no longer fits in the container, the last one is moved to second line. I would like in that case to have 2 containees in the first line and 2 containees in the second line. I dont know how to do that. Your help would be welcomed!

EDIT:
it could also be 6 containees, in the case the layout would be:
– 1 line of 6 blocks if it fits
– 2 lines of 3 blocks
– 3 lines of 2 blocks
– 6 lines of one

the number of containees is variable. I just want to have the same number of containees per line

the html:

<div class="container"> 
   <div class="containee"></div>
   <div class="containee"></div>
   <div class="containee"></div>
   <div class="containee"></div>
</div>

the css:

.containee {
  width:200px;
  height:200px;
  display:inline-block;
  background-color:tomato
}

the example can be seen here : http://cssdesk.com/uGLbq

(PS : I tried to find the solution searching the web but I dont really know the good keywords related with this topic)

  • 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-18T02:42:07+00:00Added an answer on June 18, 2026 at 2:42 am

    You can’t with CSS (AFAIK).

    You can do “the math” dynamically with Javascript in real time.

    In your case,

    • you known the width of one block (in that moment),
    • you can easily get the window width (in that moment),
    • you know the number of your block (in that moment);

    Simply apply ( (1) the first time you open the page, and (2) every time the number of blocks changes, or (3) the resolution changes) the algorithm in the following code:

    // EXAMPLE OF INPUT
    var windowWidth    = 1400;  // read it...
    var blockWidth     = 200;   // read it or use const...
    var numberOfBlocks = 10;    // read it... 
    
    
    // Calculate the maximum number of blocks per row
    var maxBlocksPerRow;
    for (var i=0; i < numberOfBlocks; i++) {
       if ( (blockWidth * (i + 1)) > windowWidth){
          maxBlocksPerRow = i;
          break; 
       }
    }
    
    // Check the highest 0 module combination while iterating backwards
    var magicNumberForMatchingBlocks = 1; // if not found, it will be 1.
    for (var i = maxBlocksPerRow; i > 0 ; i--) {
       if ( (numberOfBlocks % i) == 0){
          magicNumberForMatchingBlocks = i;
          break;
       }
    }
    
    alert("With " + numberOfBlocks + " blocks, each one wide " + 
          blockWidth + " pixels, and a window wide " + windowWidth + " pixels, 
          the number of blocks per row for having always 
          the same number of block in any row is: " + magicNumberForMatchingBlocks);
    

    Then use that number to populate or re-arrange the elements with Javascript or better with some Javascript library like jQuery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.