Internet Explorer 6: eliminate the double margin bug

Among the various funny "interpretations" that Internet Explorer 6 can do with HTML / CSS, that of the "double margin" is certainly the most tedious and often. In practice (hear, hear ...) Good Microsoft browser can - mysteriously - to double margins on items that are set to float! : As such the following CSS applied to a div with the id box :

1
display : block ; width : 100px ; height : 100px ; margin-left : 100px ; float : left } div # box {display: block; width: 100px; height: 100px; margin-left: 100px; float: left}

You get:

ie6double

Where n is the left margin of our 100px! si trova a diretto contatto con il suo contenitore. This defect, fortunately, occurs only in certain circumstances, ie when the margin coincides with the direction of the float and when our div#box is in direct contact with its container. precedente. This means that an additional div#box on the same line does not suffer because of the problem is on the left but not the container div#box above. Obviously the problem is not specific to the left margin but it specular reversing the whole thing would have the same problem with the right margin!

Solution

The solution is really simple: just insert the declaration display:inline in our CSS, and the defect disappears:

1
2
display : block ; width : 100px ; height : 100px ; margin-left : 100px ; float : left ; div # box {display: block; width: 100px; height: 100px; margin-left: 100px; float: left;
inline } display: inline}

The introduction of display:inline will be ignored by all other browsers, and not because we are particularly lucky, but rather by specific W3C :

... The 'display' is ignored, the unless it has the value 'none'.

6 comments to "Internet Explorer 6: eliminate the double margin bug"

  1. December 16, 2008 Mauritius :

    I did not understand one thing:
    in the class definition must be present both on display: block to display: inline. ?
    leaving only the second has the same defect?

    thanks

  2. December 16, 2008 Giovambattista Fazioli :

    @ Mauritius:

    I did not understand one thing:
    in the class definition must be present both on display: block to display: inline. ?
    leaving only the second has the same defect? ​​thanks

    The display:block you can replace it with display:inline

  3. December 16, 2008 Francis Gaven :

    I remember that was one of the first bug to which I was faced with IE6.
    At least in this case the solution is at least immediately (provided that you know : P )

  4. January 9, 2009 DigitaLife »IE6: Double Margin Solution Tips & GUI :

    [...] We simply explains how to eliminate the problem of double margin in IE6, the bane of web [...]

  5. December 18, 2009 Fabio:

    Are you a big, you'd do a monument! Clear, simple and fast! Great post

  6. January 15, 2010 Ivan Davis:

    You are a GREAT! it works great. now my buttons are only seen once. The command "display: inline" addresses a myriad of problems in IE.

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL