Alex Rivera | Logout

Strange float behaviour in IE7

Asked 2008-10-09T13:39:43.490
12

I want to create a simple box with a header bar containing a title and some tool buttons. I have the following markup:

<div style="float:left">
    <div style="background-color:blue; padding: 1px; height: 20px;">
        <div style="float: left; background-color:green;">title</div>
        <div style="float: right; background-color:yellow;">toolbar</div>
    </div>
    <div style="clear: both; width: 200px; background-color: red;">content</div>
</div>

This renders fine in Firefox and Chrome:

http://www.boplicity.nl/images/firefox.jpg

However IE7 totally messes up and puts the right floated element to the right of the page:

http://www.boplicity.nl/images/ie7.jpg

Can this be fixed?

Edit
Report

1 Answer

1

Got to know recently that the right floated elements need to be appended with the divs before the other elements. This is the easiest fix without adding a line of change.

<div style="background-color:blue; padding: 1px; height: 20px;">
    <div style="float: right; background-color:green;">title</div>
    <div style="float: left; background-color:yellow;">toolbar</div>
</div>
answered 2012-01-06T15:19:25.603

Your Answer