IE6 resize bug (position: relative becomes fixed)
One bug kept popping up on the sites I built, and I was almost going insane. The bug I'm talking about is specific to Internet Explorer 6 (IE6) and has to do with what happens when you resize the page. Here's an example page showing the bug. Open it in IE6 and try resizing the window. Let me explain:
Update: Paula comments that IE7 beta 2 has the same problem. Thanks Paula.
Setting up the IE6 resize bug#
To see the bug in action you need two things: You need to center your page using the body element and you need to be using a fixed width (not percent) on the element. If you use this you will quickly notice that all elements you set position: relative
on, will stay fixed on the page when you resize the window. They behave as if you just set position: fixed on them, but only until you reload. It's really a fun effect (if you know the fix).
Example code:
body {
margin: 0 auto;
width: 760px; /* Any fixed or fluid width */
}
/* Affects all elements with position: relative; */
#example p {
position: relative;
}
Here's a live example of the IE6 resize bug with borders added for clarity.
The bug is kinda rare you could say. But using body for centering is a great way of getting rid of one extra container div, so I have been using it more and more lately (IE5 can't handle that, but you don't support it do you?). Anyway, not being able to use position: relative
is not ok.
Making things behave as normal again#
Fortunately the fix is very easy. You simply add position: relative to the body element. *Blam* All previous broken elements start behaving like expected again. Here's the same example with the bug fixed.
That's a couple of hours less IE6 adoption time on my next project. I hope it helps someone out there too.
Comments
By: matthijs (#1)
So, besides this one, have you encountered other problems in container-divless layouts? I always used a container div because of the IE5 problems, but since it's time to leave that one behind I might go divless as well.
By: Emil Stenström (#2)
By: Matthijs (#3)
By: Robert Nyman (#4)
By: Robert Nyman (#5)
I'm using it to create a CSS Scrollable Table with Fixed Header and there I have it to emulate a fixed positioning.
When I add
position: relative;
to any of the parent elements to the one that acts fixed, the bug goes away (i.e. it doesn't have to be thebody
element) but then I also lose the the effect of a fixed header...By: Emil Stenström (#6)
By: stefano (#7)
Ste
By: Paula (#8)
I use IE7 BETA 2, and I had this problem.
By: Emil Stenström (#9)
By: Paula (#10)
=D
By: Lightbox feature added to JaS - JavaScript Slides - Robert’s talk (#11)
By: Roger Johansson (#12)
By: Kane (#13)
By: Emil Stenström (#14)
@Kane: Good to know you found it useful :)
By: Brian (#15)
I think it is because I had a table and table cell with align=center on the page. After I put position:relative on the element inside the centered table cell, it worked.
Thanks for pointing me in the right direction.
By: Emil Stenström (#16)
By: Ido Tzang (#17)
Do happen to have any other helpful ideas / directions ?
10x,
Ido
By: SAM0077 (#18)
By: Stuart Radley (#19)
By: Phil (#20)
By: Terry McGuire (#21)
This saved me such a headache:
ie6-resize-bug
Thank you.
By: James (#22)
By: thomas (#23)
cheers
By: Vibhore (#24)
By: Peter (#25)
By: Peter Morris (#26)
By: tim (#27)
By: sciontphono (#28)
By: Rodrigo (#29)
By: anonymous (#30)
By: Nilesh Ashra (#31)
This page was first hit on google when searching for "ie6 position resize" and fixed my problem instantly - thanks a lot :)
By: Cas (#32)
By: IE6 resize bug position: relative becomes fixed | Absolute Blog (#33)
By: Jay (#34)
By: Emil Stenström (#35)
By: kev (#36)
By: gaurav (#37)
Thanks again.
By: Michael (#38)
By: lyndonaus (#39)
By: Nathaniel B (#40)
By: James (#41)
By: Lucy (#42)
By: Jon (#43)
Jon
By: Emanuele Ciriachi (#44)
By: senen (#45)
By: volomike (#46)
By: Emil Stenström (#47)
By: Aaron (#48)
By: Smitty (#49)
By: Emil Stenström (#50)
By: Devin (#51)
By: Roman (#52)
By: Leonardo A. Souza (#53)
By: jason (#54)
the solution was simply to set the containing element to position:relative. so simple yet impossible to guess.
thanks man. you've really saved my life as i was about to go jump in front of a semi-truck just to finally achieve peace of mind.
By: Farzan (#55)
This hack saved my neck... my customer was killing me and I didn't know how I could fix it.
By: wingMan (#56)
This has been driving me nuts for the last month.
By: PavelGee (#57)
Lucky I came across your page!
By: Juan Araya (#58)
THANK YOU! THANK YOU!! THANK YOU!!!!
Had noticed this issue in some websites but was not aware I was a victim of it. A client just sent me an email complaining about this.
Thanks again for your excellent documentation.
By: Clinton Montague (#59)
Thanks again
By: Sam (#60)
By: anonymous (#61)
it's good to be informed about them.
By: Wolf Oliver Abbas (#62)
By: Michael (#63)
By: IE6???????IE6? 25+ Bugs(?) « ?????(We are UEDs,??????????????) (#64)
By: Jasper (#65)
By: daniel (#66)
By: Anurag Dwivedi (#67)
But it did not work out for me.
However, I got a solution by giving a fixed width (in px) to the parent div of problematic (those moving with resize) elements.
By: Millarian | IE7 resize window problem (#68)
By: fireguns.net» Blog Archive » [?][?]IE6???????IE6? 25+ Bugs (#69)
By: bob (#70)
By: Francesco Spreafico (#71)