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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:51:43+00:00 2026-05-14T06:51:43+00:00

As a web developer I frequently will have two floated (child) divs inside of

  • 0

As a web developer I frequently will have two floated (child) divs inside of another (parent) div. Actually I do this all day long.

<style type="text/css">
    #left {float:left;}
    #right {float:right;}
</style>
<div id="parent">
    <div id="left" class="child">&nbsp;</div>
    <div id="right" class="child">&nbsp;</div>
</div>

This doesn’t work without an extra bit of css/html because the parent doesn’t automatically grow to fit floated children. There are two popular ways of overcoming that:

1) Add overflow:hidden to the parent’s css.

2) Add a 3rd “clearing” child <br style="clear:both;" />.

I know there’s a few other similar questions about such things, but my question is:

Which method is better and why? What
are the pros and cons of each?

  • 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-14T06:51:44+00:00Added an answer on May 14, 2026 at 6:51 am
    1. Hidden overflow – pretty solid method. The main disadvantage is if you set a height on the parent element, any overflow will be…well, hidden. I found this when creating a menu with floated list items – the submenus would not appear.

    2. Clearing element – rather than a line break, I would use a div with height: 0; clear: both; since it won’t create a gap below. This is a more solid method, the only disadvantage being an extra element in the markup.

    3. Float the parent – in my experience there are too many situations where you don’t want to float the parent element, so I would avoid it.

    4. You can also use the generated content method:

      #parent:after {
        content: ".";
        visibility: hidden;
        clear: both;
      }
      

      This saves the need for an extra element in the markup, but it won’t work in IE7 and below.

    5. Use inline blocks – just remembered this method. Instead of floating the two columns, set them to display: inline-block and they will appear side-by-side:

      .child {
        display: inline-block;
        vertical-align: top;
      }
      

      Only thing you must remember with this method is if there is any whitespace between the close tag of one block and the opening tag of another, a space will appear between the columns (the size of which depends on the font so it difficult to gauge). As long as you do ...</div><div id=... then this method works fine and is superior to floating elements IMO.

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

Sidebar

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.