• Next post: SABMiller Europe Import Markets
  • Previous post: Obsidian (updated)
  • Comments
  • Leave a Reply

IE7 Bugs: No overflow to your body

posted on Tuesday, 06 February, 2007 at 9:26 am

Today, I've been developing a small elayer script for unnamed company. While testing it, I've found a nice bug in IE7 that can pretty mess up your life…

No overflow to your body. Yes! Thats right. A single script could mess my time around. But let's get to the point.

In most of my script where I use to display an e-layer, I usually set html body to width:100% and overflow:hidden. But today I noticed everything worked fine except IE7. To test it I minimized HTML document and code below is my output:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
        <head>
                <title>IE7 Bug test</title>
                <style type="text/css">
                body{
                        overflow: hidden;
                }

                div{
                        width: 4000px;
                        height: 4000px;
                        background:red;
                }
                </style>
        </head>
        <body>
                <div></div>
        </body>
</html>

IE7 will not apply overflow:hidden to body when the xml declaration and doctype is stated! It seems guys in Micro-soft messed up with Trident parser a little bit more than expected.

The easiest way (and only one I found today) how to correct it was to set same definition to html element. So while using previous contruction will not affect the gorgeous scrollbars while you don't need them using one below will.

html{
        overflow: hidden
}

How simple ;) So remember try to define html and body together while in css, and setting document.documentElement or document.getElementsByTagName("html")[0] while in javascript to hide scrollbars in your pages…

Good luck folks!

Comments

  1. D Carter says:

    Thank you, thank you, thank you! I’ve wasted so much time trying to find the issue here and this has exactly fixed it! I can’t thank you enough. Great job.

  2. hrax says:

    [1] with pleasure d. I’m glad it helped u.

  3. Maxwell says:

    Wow thanks you just saved me!!! I don’t even wan’t to think how long it would have taken me to figure this one out :)

    In my case it didn’t work in IE6 either :/ using:
    document.body.style.overflow

    You pull my trigger then you blame my gun, and nothing pulls triggers more than IE!

    Greets & Thanks,
    maxwell

  4. ManuMie says:

    You are a great CSS master, thank you so much !

  5. pata says:

    Thank you so much for posting this. Been wasting my time finding out what was wrong! IE7 again…(sigh)

  6. André says:

    thanks man. this post save my sanity!

  7. Tom says:

    Hey there…

    Thanks a lot for taking the time to document this!

    I’ve spent the last 1/2 hour trying to find out why IE7 has yet more problems…

  8. Peter says:

    Thanks, this really helped me out!

  9. kasio says:

    YOU

    ARE

    A

    GOD!!!!!

  10. Tine says:

    Gracias :)

  11. Akila says:

    Thanks a Lot…..Every where they have given that it will not work in IE so i was not able user that.After seeing urs i was soooooooooooo happy and it works very fine in all the browsers. Thanks a lot. :):)

  12. Claudio says:

    Thanks a lot.

    Here, in Brasil, I didn´t find no one site to help me about this.

    You´re great.

  13. Andre says:

    thanks man, you saved my ass!

  14. Nils says:

    U sir, are this mondays hero!

  15. shahvez says:

    hey thanks a lot…it really help me out.

  16. Zoffix Znet says:

    Hey!

    I'd like to note that Microsoft didn't really mess anything up here – as far as I know the spec doesn't mention what the default overflow value should be for the root element, which is what this issue is about.

    The in your case would not hide any overflow because there is no height/width set on it. The reason sane browsers hide it is because in them element's overflow is set to visible and thus, as per spec's section 11.1.1, the overflow value from is transfered onto the viewport. IE simply has a different default on .

    If you want to read up in more detail, see my tut on the subject: http://haslayout.net/css/view?…

    Cheers!

  17. Zoffix Znet says:

    Ugh, you should have a note that <foo> would be stripped off the comments completely :/

    Here's what I meant to say:

    Hey!

    I'd like to note that Microsoft didn't really mess anything up here – as far as I know the spec doesn't mention what the default overflow value should be for the root element, which is what this issue is about.

    The <body> in your case would not hide any overflow because there is no height/width set on it. The reason sane browsers hide it is because in them <html> element's overflow is set to visible and thus, as per spec's section 11.1.1, the overflow value from <body> is transfered onto the viewport. IE simply has a different default on <html>.

    If you want to read up in more detail, see my tut on the subject: http://haslayout.net/css/view?…

    Cheers!

  18. blah says:

    You're awesome and you deserve a truckload of internets.

  19. Srle says:

    This option work in IE7
    #wrapper {
    overflow: hidden;
    }

    and make an exception for IE7 in code of page:
    <!--[if IE 7]>-->
    #c1, #c2 {padding-bottom: 1000em; margin-bottom: –999.5em; height: 100%!important;}

    c1 and c2 are column div-s
    I lost 5 hours on this

    @%#!!!??? Microsoft and bugs

  20. Valentin says:

    Thank you very much for your fix. Just saved my day :)

Leave a Reply

Personal information
Body

All fields marked with * are required.