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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:22:11+00:00 2026-06-11T23:22:11+00:00

I have a (horizontally) centered outer div containing two elements of unknown width: <div

  • 0

I have a (horizontally) centered outer div containing two elements of unknown width:

<div style='width:800px; margin:0 auto'>
  <div style='float:left'>...</div>
  <div style='float:right'>...</div>
</div>

Both floats are top-aligned by default, and are of varying/unknown and different heights. Is there any way to make them vertically centered?

I eventually made the outer div

display: table

and the inner divs

display: table-cell;
vertical-align: middle;
text-align: left/right;

but I’m just curious if there’s a way to do this with the floats.

  • 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-11T23:22:12+00:00Added an answer on June 11, 2026 at 11:22 pm

    You can’t do this directly, because floats are aligned to the top:

    If there is a line box, the outer top of the floated box is aligned
    with the top of the current line box.

    The exact rules say (emphasis mine):

    1. A floating box’s outer top may not be higher than the top of its containing block.
    2. The outer top of a floating box may not be higher than the outer top of any block or floated box generated by an
      element earlier in the source document.
    3. The outer top of an element’s floating box may not be higher than the top of any line-box containing a box generated by an
      element earlier in the source document.
    1. A floating box must be placed as high as possible.

    That said, you can take advantage of rule #4:

    • Place each float inside inline-level elements that establish a new block formatting context /BFC), e.g. display: inline-block.
    • These wrappers will contain the floats because they establish a BFC, and will be one next to the other because they are inline-level.
    • Use vertical-align to align these wrapper vertically.

    Be aware that some space might appear between the inline-block wrappers. See How to remove the space between inline-block elements? to fix it.

    .float-left {
      float: left;
    }
    
    .float-right {
      float: right;
    }
    
    #main {
      border: 1px solid blue;
      margin: 0 auto;
      width: 500px;
    }
    
    /* Float wrappers */
    #main > div {
      display: inline-block;
      vertical-align: middle;
      width: 50%;
    }
    <div id="main">
      <div>
        <div class="float-left">
          <p>AAA</p>
        </div>
      </div>
      <div>
        <div class="float-right">
          <p>BBB</p>
          <p>BBB</p>
        </div>
      </div>
    </div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a horizontally centered div #box1 that has margin: 5px auto that has
I've successfully centered horizontally my overlay dialog with margin: 0 auto;. But I have
ive created a lightbox where I have centered the div horizontally and vertically with
I have 2 divs that positioned horizontally ( float:left; width:50%; ). But i want
My goal is to have several images displayed horizontally centered within a div which
I have several uniform blue elements ( <div style=display: inline-block;> ) inside a red
The <center>Text</center> tag to have text centered horizontally is depreciated, so I tried <p
I have the following code to draw text centered vertically (and horizontally) in a
I have one horizontally div on the top of my page with a height
I have a horizontal unordered list I want to center horizontally in a div

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.