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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:55:19+00:00 2026-05-14T08:55:19+00:00

so i have 4 divs (i actually have many more but this will simplify

  • 0

so i have 4 divs (i actually have many more but this will simplify the question). i want to display them in two columns. the 4 divs vary in height. the number of actual divs in the end will vary.
so if i have this

<div id="1" style="height: 200px" class="inline">some content here</div>
<div id="2" style="height: 600px" class="inline">some content here</div>
<div id="3" style="height: 300px" class="inline">some content here</div>
<div id="4" style="height: 200px" class="inline">some content here</div>

with styling thus

.inline { display: inline-block; vertical-align: top; width: 48%;}

so #1 would go left and then #2 would shove up beside it to the right, great, but the #3 will not slide up the 400px to fit nicely below #1. (of course)… it goes on the left side but at 600px from the top clearing the bottom of #2. etc…

how would i get the divs to slide up into the empty spaces, is it possible with css? jquery maybe?
i know i could write column divs to mark it up, but since the number of divs constantly change and the heights vary according to content. It would be nice to just get rid of the space since we dont really care about the order.

any thoughts?

  • 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-14T08:55:19+00:00Added an answer on May 14, 2026 at 8:55 am

    Unfortunately this is impossible with pure CSS, you are going to need separate divs for each column. Fortunately, you can achieve this using jQuery. Something like this should do the trick:

    $(function() {
        var odd_divs = $('div.inline:odd');
        var even_divs = $('div.inline:even');
        var left = $('<div id="left-column" class="column"/>').append(odd_divs);
        var right = $('<div id="right-column" class="column" />').append(even_divs);
        $('#somewhere').append(left).append(right);
    });
    

    And change your CSS to this:

    .column {
        width: 50%;
        display: inline-block; 
        vertical-align: top;
    }
    

    EDIT

    As Brian McKenna noted, it is actually possible to achieve this effect using CSS floats. You can use jQuery to add the classnames as so:

    $(function() {
        $('div.inline:odd').addClass('box-left');
        $('div.inline:even').addClass('box-right');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two divs which I want to simulate a slider but not actually
I have divs that I want to display at specific times throughout the day.
I have 2 divs that positioned horizontally ( float:left; width:50%; ). But i want
i have 2 divs, the blue one is set to 365px width (this will
I have this jQuery script which make my two divs the same height: $(document).ready(function
I don't know how to ask this without a picture. I have two divs,
I have two forms on a single page. Actually they're seperated pages but the
I have two images they actually do not overlap but I also can't have
Have three divs in a container that I want to float over a large
I have two divs floated next to one another: <div id=parent> <div id=child_1 style=float:left>

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.