Post details: Fixing the PC IE "float drop" bug

Mon February 7, 2005

Permalink 05:13:55 pm, Categories: Internet & technology, 468 words  

Fixing the PC IE "float drop" bug

I am so excited. I've been plagued for a year by an Internet Explorer bug called the "float drop" bug (detailed nicely here). Basically, if IE tries to put an element next to a floated element, and the non-floated element is too wide for the container block, it drops the non-floated element down to AFTER the floated element.

We have a site with a three-column layout, and many different users entering content into the site. This bug has cropped up from time to time, usually when someone has input an image that's too large for the browser window or a table that's a bit too wide. It has the effect of looking like your content has simply disappeared, because it pushes it down after the left-hand menu. And I've hated having to tell people to alter their content just because Microsoft screwed up, but damn, I could not find the answer anywhere. A few workarounds, but nothing that applied to my situation.

Today I finally got mad enough to dig down and hack out a proper solution. And I found one:

* html #middle {
    overflow-x: auto; overflow-y: hidden; 
    width: expression(document.body.offsetWidth - 400);
}

What this does:

  • "middle" is the non-floated container block into which the content goes. There are also columns named "left" and "right" on certain pages.
  • The * html bit only applies to IE, so all other browsers will ignore it. This is better known as the Tan hack.
  • The overflow statements place a horizontal scrollbar at the bottom of the block, when needed.
  • The width takes advantage of Microsoft's proprietary "expression" tag to fix the browser's own bugs - it calculates the width of the block to be the width of the page minus some predetermined offset (in this case, the width of the two columns plus some padding). So IE will pop up the horizontal scrollbar whenever the content exceeds this dynamically-determined size.
  • I found I needed to add quite a bit of extra padding to get it to work (I added 50, but probably could have gotten away with less). 10 or 20 more didn't cut it. It's probably extra space for the scrollbar. I could muck with it and see exactly what the difference is, but I'm happy with it as is - in the worst case you have a slightly narrower content window.

I'm very happy with the final effect - the other browsers continue to behave nicely as they already were, and IE shows a discreet little scrollbar at the bottom of the page if the content is too wide. It lets the user view the site in a much narrower window without going wonky. And if the content editor wants to fix the width so the scrollbar doesn't appear, then that's fine too.

Tested in IE5.5 and IE6.0 PC. I hope this helps somebody else out too.

Comments, Pingbacks:

Comment from: JC [Visitor] · http://www.getfirefox.com/
If I didn't suspect it was work-related, I'd say leave the bug there, and tell site viewers to use a real browser, like Firefox. :D
Permalink 02/08/05 @ 10:00
Comment from: Paul D [Visitor]
I encountered the float drop bug today. It took me a long time to work out a solution; what finally solved it for me was to give my floating sidebar a negative margin fully equal to the width of the sidebar. Like so:

#sidebar {
width: 200px;
float: right;
margin-right: 60px;
}

* html #sidebar {
display: inline;
margin-left: -260px;
}

The "display: inline" is there to fix IE's double-margin bug. Man, I wish I could just design for Safari and Firefox. :)
Permalink 08/25/05 @ 20:37
Comment from: Judith Gibbons [Visitor]
Probably a little late to get feedback on this, but I've only just found the page. I have tried to fix a similar problem (on www.cel-international.com) where occasionally a page has a large graphic on it (e.g. on www.cel-international.com/company/location.htm). However, when I tried to print a page (there is a separate print css style sheet) it printed the window at the width it had been viewed at, so it could be very narrow or too wide for all the text to fit on the page. I tried putting the hack code in the print style sheet with different values but it didn't reset itself! Anyone else had this problem?
Permalink 05/31/06 @ 08:24
Comment from: Trevor [Visitor]
I. Love. You.

I've been looking for exactly this fix for toooooo long! Found a little workaround myself but this one's perfect. Thank you much!
Permalink 07/17/06 @ 23:45
Comment from: Bridges [Visitor] · http://www.kasonbridges.com
Hey,

i encountered this problem today and spent the last 4 hours with going mad on this.
Thank you so much for this solution!
Permalink 10/07/06 @ 08:41
Comment from: Denis Mishunoff [Visitor]
Thank you so much for that overflow-x: auto; tip. That fixed my problems! I was almost dead while trying to fix view in IE and you saved my life! Thank you once again :)
Permalink 11/14/06 @ 01:43
Comment from: Steve [Visitor]
Great fix. Stupid Micro$hit with their dumb browser causing all kinds of problem. World would be so much better without them.
Permalink 11/19/06 @ 17:10
Comment from: Dorax [Visitor] · http://holistic-vibes.com
I love you!

But I just used:

overflow-x: auto; overflow-y: hidden;
width: expression(400);

where 400 is the desired width of my div.

Lets just hope there are no more surprises in other versions of IE!

Thanks¨!
Permalink 01/24/07 @ 06:42
Comment from: Gamliz [Visitor]
Thank you, sir.

It works wonders.
Permalink 02/02/07 @ 02:16
Comment from: Beau [Visitor] · http://www.foxhavenjournal.com
Thank you! I modified your hack for my CSS (changing #middle to #primarycontainer, and decreasing Width) and the text/sidebar will now display together at all screen resolutions. Interesting... I tried many other CSS hacks to achieve same w/ IE6, but this is the only one that worked!
Permalink 02/08/07 @ 21:42
Comment from: Bazzoola [Visitor]
Has anyone tried to File -> Print ?

It crashed my IE6 and many IE6's on different setups/workstations.

Once this hack is removed printing functions normally.

Thanks!
Permalink 02/21/07 @ 00:04
Comment from: Tamcy [Visitor]
This is really awesome. Thank you very much!
Permalink 04/13/07 @ 04:02
Comment from: Dimitar Ivanov [Visitor] · http://www.bg-news.org
That's great fix. Thanks.
Permalink 04/27/07 @ 02:55
Comment from: Allan Bogh [Visitor] · http://www.allanbogh.com
Another way to fix this is to use this code, which specifies the precise width to set the div to:

* html #middle {
overflow: hidden;
width: expression(document.body.offsetWidth - (document.body.offsetWidth - 40));
}

The div will be 40px wide.

You can also just use this code to fix the problem:

overflow:hidden;
width:100%; /*relative to the allowed amount of space*/

The second option seems to apply when you have a div within a div that has a set width.
Permalink 05/31/07 @ 20:52
Comment from: Pablo [Visitor]
You just saved me another 4 hours. Thanks man.
Permalink 06/05/07 @ 04:08
Comment from: John Lockwood [Visitor] · http://www.sacramento-home.com/real-estate-events/
Was just trying to fix something on ParticleWave.com -- same bug. Thanks for the fix!
Permalink 08/08/07 @ 02:36
Comment from: Simon [Visitor] · http://www.ctcalderdale.org.uk/
Thank you very much. This has been a great help.
Permalink 08/13/07 @ 03:19
Comment from: big anz [Visitor] · http://www.nuggetsinsider.com
thanks a bunch i have been searching for a fix to this nasty little bug all morning -- after a couple hours of looking for a fix -- after going through many options i think your fix is by far the most convincing ive come across --- ill give it a shot -- domo
Permalink 08/17/07 @ 09:29
Comment from: Thomas [Visitor] · http://www.shahent.com
i tried all of the suggestions above and nothing is working for me. can someone give me any advice more specific to my html code.
Permalink 10/01/07 @ 16:51
Comment from: ramon [Visitor] · http://anime-list.net/
It fixed my site problem for ie.
stupid ie but thanks to you that is 1 bug less to worry about.
Permalink 11/18/07 @ 04:38
Comment from: Lindsey Simon [Visitor] · http://www.dishola.com
Robert Nyman sums up this hack pretty handily:
http://www.robertnyman.com/2007/11/13/stop-using-poor-performance-css-expressions-use-javascript-instead/
Permalink 01/16/08 @ 08:27
Comment from: Ranccis [Visitor]
@ Paul D

thanks man, you helped solve this big mindwreching problem.
and you thoughts are mine exactly, FF and Safari.
thks,
Permalink 04/17/08 @ 11:55
Comment from: mary [Visitor]
Very nice fix. Maybe you should sell the idea to Microsoft to patch the IE once and for all.
Permalink 06/24/08 @ 11:02
Comment from: Brian [Visitor]
My site consists of 4 columns of different widths. In column 2, I have a very wide banner. In Mozzila, the banner overflows into column 3 and looks beautiful. However, in IE column 2 drops all the way to the bottom. Any advice for me?
Permalink 11/09/08 @ 23:37
Comment from: Brock Tice [Visitor] · http://virtuallyshocking.com
THANK YOU! This has wasted an hour of my time this morning already. Glad to have it fixed.
Permalink 02/25/09 @ 10:09
Comment from: Ben H. [Visitor] · http://netmanageit.com
Thanks! This worked perfectly for me.

I had so many issues with theming a drupal site to display properly in IE6 that I created a separate stylesheet conditional on an IE6 user agent so everyone else wouldn't have to suffer because of the select few who stubbornly persist in using an antiquated browser.
Permalink 04/01/09 @ 16:51

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.
Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, a, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
URLs, email, AIM and ICQs will be converted automatically.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)

crows to burnaby

Kirsten Starcher lives in Vancouver, BC, spending half her time as a musician, playing bass in ARCTIC as well as solo, and the other half as a web designer/developer.
You can contact her at "kirsten at crowstoburnaby dot com" (turn it into a proper email address, of course!).

Search

Photos on flickr



Likeable links

my del.icio.us things

Blogroll




Syndicate this blog XML

What is RSS?

powered by
b2evolution