Accessibility

CSS Advisor

Float Drop - floated elements drop below their expected position.

by CSSAdvisorAdmin on November 17, 2006
Edited by: sfegette on November 24, 2009
Avg Rating 2.8 (21)   |   Log in to rate post.

Tagged with Explorer 6.0 , Explorer 5.0 , Position , Explorer 5.5 , Float , Explorer for Mac

Problem

If a container (including the body) is not wide enough to display both a float and the static content that follows it side by side, the static content will drop below the float instead of wrapping around it.

Solution

Wrap content in a fixed-width container large enough to accommodate the content, or remove the width from the static block.

Detailed description

If a container (including the body) is not wide enough to display both a float and the static content that follows it side by side, the static content will drop below the float instead of wrapping around it in Internet Explorer.  This is most frequently caused by an 'unwrappable' text string or inline element that is wider than the container element.   Even if you explicitly state a width, IE 6 and earlier versions will not allow the 'unwrappable' element to overflow and maintain the correct width, which results in the corresponding floated element to 'drop' below it's predecessor.

For example, using the following HTML code:

<div id="wrapper">
<div id="header">Site Header</div>
<div id="nav">Left Nav withverylongandunbreakabletextstring</div>
<div id="content">This is where my main text goes.</div>
<div id="footer">Site Footer</div>
</div>

and the following CSS code:

#header { 
background-color: #FFFFFF; }
#nav {
background-color: #FF0000;
width: 50px;
float: left;  }
#content {
background-color: #00FF00;
width: 350px;
float: left; }
#footer {
background-color: #0000FF;
clear: both;  }
#wrapper {
width: 400px; }

Firefox/Safari will allow the 'unbreakable' text string in the #nav div to overflow correctly and let the next div - #content - to float alongside it as expected:





Whereas in IE, the #nav div will expand beyond it's stated width, and the #content div will drop down below the #nav div (i.e. float drop).



IE6 will also drop a float due to use of italicized text that should fit comfortably inside the box. The fix for that is to set word-spacing on the paragraph containing the italicized text to 1px.

The infamous 3-pixel text jog bug can also cause float drop, and may be a cause of this occurring in absence of any other discernable trigger case.  If you're debugging and running into a wall, make sure to use the Holly Hack to get around the 3-pixel text jog bug and see if that helps clear up the float drop bug as well.


This bug was documented by artcoder and Big John at positioniseverything.net- be sure to check out the artlcle there for much more detail and information. 

Big thanks to Al Sparber for calling out version specificity, and providing the italics bug that can also cause float drop (and it's fix).


firefox_floatdrop.jpg
ie_floatdrop.jpg




Text ID: FLOAT_DROP



Comments (10)

To add a comment, please Log in.




Fixed

Thanks gabemejia, I removed the width and the error disappeared

Firefox Float Drop

Thanks for the detailed article. I am having a similar issue with a website dropping the right content div under my left nav div. It is only happening in Firefox 3, and it's randomly occurring, so it's very hard to browser test. It displays properly after a page refresh. I've tried the suggested fixes and validated my code and css with w3c. Can anyone offer suggestions? Thanks.

www.ascendantlab.com

images?

The images are still not showing

Missing Screencaptures

The screenshot images that appear below the code are missing from your web page.

All I had to do was

All I did was to remove the "width=xxxxpx" section and the error was gone.

Utilize margins and inherited positioning

To make sure your main content is not affected  by the size of the Left Nav , take out the positioning and size of the main content  and give it a margin of the same size as the Left Nav. e.g
#content {
  background-color: #00FF00;
  margin: 50px;  
}
Add div or element with a .clear after the main content to make sure any  floated divs inside the main content do not overflow into your footer

IE ~ The outlaw of CSS

IE should not be allowed on the web ;-) Use Firefox, Safari, Opera or basically anything else that is W3C compliant.

Details

"IE" should be qulaified better - as to version. IE7 will, in fact, overflow its box as do other modern browsers. That said, IE6 will also drop a float due to use of italicized text that should fit comfortably inside the box. The fix for that is to set word-spacing on the paragraph containing the ilalicized text to 1px. While the italics bugs might be noted elsewhere, it should be mentioned in this tech note as it will drop a float for reasons not yet covered here.

Post updated

Thanks Lori, I've updated the post with more detail, example code, and screenshots of the correct/incorrect behavior (and a link to the 3-pixel text jog bug)!

Need more detailed info.

This post needs more detailed info and screenshots (and a link to the Three Pixel Text Jog issue, since that can cause Float Drop).





CSS Advisor home
Submit a post

rss

CSS ADVISOR RSS FEEDS
Recent: POSTS | COMMENTS | EDITS


Browsers
Internet Explorer (45)
Mozilla/Firefox (16)
Opera (7)
Safari (13)
CSS Properties
Background (6)
Border (3)
Color (1)
Float (15)
Font (1)
Margin (6)
Padding (4)
Position (15)
Text (13)
Width/Height (9)