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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:59:02+00:00 2026-05-23T14:59:02+00:00

So I was fiddling around with CSS and floating the other day and stumbled

  • 0

So I was fiddling around with CSS and floating the other day and stumbled upon an odd behavior (frankly I’m surprised I hadn’t encountered it before). I was puzzled as to the reason for it (as well as to why I didn’t already know…).

If you have a div (let’s call him Bob) and you try to float him next to another div (Jimmy), it only works if

  1. Jimmy is floated too
  2. Jimmy comes after Bob

So if we have:

<div class="container">
    <div id="one">Main Content 1</div>
    <div id="two">Sidebar 1</div>
</div>

with

.container { 
    overflow:hidden; /* this essentially clears the floats. You could remove it and add a clearfloat div instead */
    margin-bottom:10px;
}
#one {
    background-color:red;
    margin-right:50px;
}
#two {
    width:50px;
    float:right;
    background-color:blue;
}

we get;
enter image description here
but if we just swap #one and #two, keeping the same CSS:

<div class="container">
    <div id="two">Sidebar 2</div>
    <div id="one">Main Content 2</div>
</div>

we get:
enter image description here

Why? I’m sure it’s something simple (which makes me feel stupid) related to the box model and the definition of float, but what?

You can fiddle with it here

  • 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-23T14:59:03+00:00Added an answer on May 23, 2026 at 2:59 pm

    This is expected behavior.

    First remember that floated elements are not part of the normal flow. The rest is in the following spec:

    A floated box is shifted to the left
    or right until its outer edge touches
    the containing block edge or the outer
    edge of another float. If there is a
    line box, the outer top of the floated
    box is aligned with the top of the
    current line box.

    Basically your second example pulls div#two out of the document flow and shifts it to the right until it touches the outer edge of its sibling, div#one. Since it has margin: 50px;, there’s enough room for div#two to fit.

    Your first example, div#one has already cleared that line as a block level element and therefore div#two is floated right and aligned with the top of the current line.

    Read more from the W3C CSS2.1 Specification on Floats

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

Sidebar

Related Questions

Guys, good day. im starting to learn mysql and still fiddling around. I just
I'm fiddling around with a possible way to run some chunks of this stuff
I have been fiddling around with server side interceptors on CXF. But is seems
I'm just fiddling around with user scripts in chrome right now, so please bear
I'm currently fiddling around with contenteditable=true to create a syntax highlighted input box. I'm
I'm using Visual Studio and while fiddling around with a custom control, I started
ok, so I'm doing ProjectEuler Problem #14, and I'm fiddling around with optimizations in
Remember, this is using python. Well, I was fiddling around with an app I
While fiddling around with a custom look for the web interface for svn over
I have been fiddling around with settings for a while, and cannot seem to

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.