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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:54:44+00:00 2026-06-05T08:54:44+00:00

I have two quite narrow (width:400 px) divs that should be stacked vertically if

  • 0

I have two quite narrow (width:400 px) divs that should be stacked vertically if there is sufficient vertical space in the browser window. If the browser height is too small and there is space enough to the right, the “bottom div” should float to the right of the top div.

In a sense I’m asking for the opposite to “float:left”. float:left align divs horizontally if there is sufficient horizontal space in the browser window and only float divs below the others if there only is available space below them.

Thanks for any suggestions!

  • 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-05T08:54:45+00:00Added an answer on June 5, 2026 at 8:54 am

    Depending on the level of browser support you require, a simple media query may solve your problem:

    <!doctype html>
    <html>
        <head>
            <style>
                /* SET THE DEFAULT RULES FOR SHORT SCREENS */
                .bottom-floaty {
                    height:200px;
                    width: 400px;
                    margin: 15px; padding: 10px;
                    outline: 1px dashed #aaf;
                    }
                /* HERE FOLLOWS THE MAGICAL MEDIA QUERY FOR TALL SCREENS */
                @media all and (max-height: 500px) {
                    .bottom-floaty { float:left; }
                }
            </style>
        </head>
        <body>
            <div class="bottom-floaty">
                I'm a sometimes floaty div
            </div>
            <div class="bottom-floaty">
                I'm also a sometimes floaty div
            </div>
        </body>
    </html>
    

    Here’s the effect I see with that:
    In a tall window
    In a short window

    The CSS3 media queries let you set any rules css you like based on the viewport height. The w3c has lots of information about media queries.

    A relevant snippet regarding viewport height:

    The ‘height’ media feature describes the height of the targeted display area of the output device. For continuous media, this is the height of the viewport including the size of a rendered scroll bar (if any). For paged media, this is the height of the page box.

    A specified cannot be negative.

    Sometimes I find the Mozilla Developer Network a bit more accessible, but in this case they provide basically the same information.

    Do you need to support old browsers who can’t render media queries? It should be fairly simple to write a javascript polyfill can have the same effect, especially using a library like jQuery.

    Edit

    I revised my code example to more closely match your problem. You commented:

    Jashwant: putting the div below the other is always preferred. So it’s only in the case that there’s space to the right but not at the bottom, that div2 should go to the right of div1. – Jonas

    And I also set the widths to 400px as in your example.

    Now it only floats left if the screen is too short for them to be vertical and there is sufficient room on the right to fit both. Otherwise it’s always vertical.

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

Sidebar

Related Questions

I need an XML-serializable dictionary. Actually, I now have two quite different programs that
I have two click-events, that are nearly similar, but not quite. I am wondering
I'm quite a beginner at database design. I have two problems that I'd like
Quite simple really. I have two ContentPanes that I load content into dynamically. The
If I have two interfaces , both quite different in their purposes , but
This is somewhat related to this question , but not quite. I have two
I have two XML files. The first XML has a bunch of nodes that
I have two web applications in ASP.NET which are quite the same (same business
In my application I have two queries which will be quite frequently used. The
I have an issue where I have two pages that deal with very similar

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.