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

The Archive Base Latest Questions

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

I have two floats inside a div with display:table and margin:auto. It works fine

  • 0

I have two floats inside a div with display:table and margin:auto. It works fine centering these two divs. However when I make window smaller, one of the floats drops down like it should, but the wrapper doesn’t shrink to the new size and so floats inside become aligned to the left instead of being centered. How do you make it shrink appropriately? I mean, display:table is supposed to shrink, why does it not??

So this is what I have originally with large window size

+----------------+ - div {display:table, margin:auto}
|+-----+  +-----+|
||float|  |float||
|+-----+  +-----+|
+----------------+

After making browser window smaller, div size remains the same instead of shrinking to accommodate new float position. It looks like this

+--------------+
|+-----+       |
||float|       |
|+-----+       |
|+-----+       |
||float|       |
|+-----+       |
+--------------+

And this is how it should look

    +-------+
    |+-----+|
    ||float||
    |+-----+|
    |+-----+|
    ||float||
    |+-----+|
    +-------+

Any ideas how to make this work? Is there way to do it without media queries?

Here is a sample code: http://jsfiddle.net/WerPx/1/
It works as intended with larger window size, but if you make the result window smaller, one of the floats goes underneath, but green wrapper doesn’t shrink to accommodate the new size.

  • 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-14T09:19:19+00:00Added an answer on June 14, 2026 at 9:19 am

    Seems like you are trying to make a responsive layout. In your example, you just need to set width: 100% to the wrapper. But if the design is a title more complicated (horizontal nav, footer, sidebar…) then is a good idea use media queries, something like this:

    @media (max-width:800px), projection {
      /* The browser window width must not exceed 800px or this device
         must be projected media for these rules to apply */
     }
    
    @media screen and (min-width: 500px) and (max-width: 800px) 
    { 
       /* style sheet that is usable when the viewport is between 500 
          and 800 pixels wide */
    }
    

    Further reading:

    • Responsive Tutorials and Guidelines in Smashing Magazine
    • Adaptive layouts with media queries (tutorial)

    EDIT: For your code this is the solution using media queries: http://jsfiddle.net/WerPx/2/

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

Sidebar

Related Questions

The idea: I have a container div with two divs inside of it, like
I have two divs inside a container div. One need to float left the
I have two inner divs which are nested inside a wrapper div. I want
I have two divs inside a div, I want them both adjacent to each
I have a div with two nested divs inside, the (float:left) one is the
I have two divs and a wrapper div around them. The wrapper div is
I have two divs inside a containers floating to the left. In some of
I have a two-column layout, composed of fixed-width floated divs. Inside the first column
Currently I have two div boxes 1 & 2 with text, inside a 3rd
I have a div called block_inside. In it, there are two divs, text_block and

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.