Subscribe to RSS

CSS fix for the double margin float bug in IE6

There are several well known bugs that affect only Internet Explorer 6 that can wreak havoc on your websites. One of the most annoying is the double margin float bug in IE6, simply if you float a block level element to the left it will double the margin you have applied to the element and most of the time break your site entirely in a strange way.

This first image is how you wanted the site to look.

normal website

This image is the site broken.

IE6 double margin float bug

When you typically see something broken like this in IE6 it is the double margin bug that is to blame. One of the easiest ways to fix it is to simply not use margin on the same direction as you are floating the object. This can be a little tricky to get the hang of though. For instance, when you have your two floated columns inside of a container you can add padding to that container in order to avoid using margin.

If you are looking for a quick fix to this problem you can always use the IE6 if statement to target IE6 specifically and half the margin being used in your floated objects.

Just keep in mind that it is not all floated objects that get double margin in IE6. Internet Explorer 6 will only apply double margin when you are using margin on the same side of the object as you are floating it. Either way, it is important to be aware of these bugs in IE, unfortunately there is still a large portion of the population still using IE6. As of April 2008, 24% are using IE7 and 28.9% are using IE6.

Popularity: 8%

Whats Next?

  • Save to Delicious! Save the page

10 Responses to “CSS fix for the double margin float bug in IE6”

  1. Sean Farrell Says:

    There is actually a very easy way of fixing this, just add “display:inline;” to the floating objects and it will fix the problem. No need for IE6 if statements or secondary stylesheets.

  2. Dustin Brewer Says:

    Adding display:inline to divs you are floating can have unexpected results, especially when it comes to crossbrowser compatibility.

    The other problem with using display: inline is that it is essentially a hack that only applies to IE6. You don’t want to create those in your main stylesheet and if you are going to the trouble of specifying IE6 only you might as well correct the margin to be half.

  3. Vasilis Says:

    What I usually do is to replace the margin-right:20px; with position:relative;right:20px;

  4. Claire Says:

    Vasilis your tip worked for me, thanks!

  5. bigtime Says:

    You can also just set a different margin for IE6 browser:-

    /* IE6 Only */
    * html #rightcolumn{
    margin-left: 20px; }

  6. Wim Says:

    By editting the CSS with what bigtime said worked for me.
    I had a problem with the margin in IE6. It worked fine in IE7 and firefox:

    .xml_blok
    {padding:10px 0px;
    margin:10px 10px 10px 18px;
    text-align:center;
    width:220px;
    height:300px;
    border:none;
    background-image: url(../images/borderkantoormachines.gif);
    background-repeat:no-repeat;
    float:left;}

    So I included this:

    /* IE6 Only */
    * html .xml_blok
    {padding:10px 0px;
    margin:10px 10px 10px 10px;
    text-align:center;
    width:220px;
    height:300px;
    border:none;
    background-image: url(../images/borderkantoormachines.gif);
    background-repeat:no-repeat;
    float:left;}

    Thanxs for your help

  7. NETTUTS - Solving 5 Common CSS Headaches Says:

    […] Visit Article […]

  8. agencja modelek Says:

    finally found what I sought! thx for this fix!

    regards, AM

  9. katalyst Says:

    omg finally

    bigtime thank you! i’ve been looking for a solution and yours works for me.

  10. Bill Brown Says:

    I was under the impression that floated elements are treated as display:block regardless of what you specify in your stylesheet. Don’t other browsers simply ignore display:inline and treat the float as a block?

    I’ve used this approach for a few years now and haven’t seen any drawbacks. Which browsers produce unexpected results?

Leave a Reply


Recent comments

I’ve been on a vacation, normality will happen next week

On August 28, 2008, holiday travel wrote:

well this is useful… (at least for me) very thanks ————&# 8212;———R 12;—–...

Top 10 search engine optimization techniques

On August 26, 2008, ибп wrote:

А что, неплохо!

Styling the first post of your Wordpress blog

On August 21, 2008, cheap website design wrote:

good point you have in there! thanks for sharing with us

CSS Hack:Getting Safari to behave

On August 21, 2008, Glass wrote:

You can also target Safari with the following: body:first-of-type .class {} That is: just prepend css the rule with body:first-of-type. Simple.

Styling the first post of your Wordpress blog

On August 20, 2008, jeeremie wrote:

Hi, This solution didn’t work for me. Instead, I use this one »