The other day when working on my latest website; I had everything working fine until I decided to check how things looked in IE. Usually IE7 plays pretty well, but in this instance there was a pretty crucial problem. I had an absolutely positioned div (hover menu) and under it I had a transparent PNG that was also absolutely positioned as well.

The absolutely positioned div had a z-index of 1000, but @jorenrapini pointed out that IE doesn’t use z-index properly. I came across this quirksmode.org article that explained the flaw in detail:
“In Internet Explorer positioned elements generate a new stacking context, starting with a z-index value of 0. Therefore z-index doesn’t work correctly”
The above article does not contain a workaround but in the comments a fellow mentioned that giving the parent element a higher z-index actual fixes the bug. Don’t ask me why this works but it does!
<div style="z-index: 3000">
<div style="position:absolute;z-index:1000;">
<a href="#">Page</a>
...
</div>
</div>
<img style="position:absolute" src="myimage.png" />

If you liked this article please keep updated by subscribing to my RSS feed, and following me on twitter (@brenelz)
Nice trick! Thanks!
Good tip, bound to come across it sometime as I have started to use absolute positioned divs now.
February 6th, 2009 at 10:59 am
I have run into the same problem. My dropdown nav divs would appear behind the main promo div in IE 7 and IE 6. I couldn’t find a solution online at the time. I experimented and ended up using a z-index of -1 on the promo div for IE 7 and lower. That seems to work fine, but I couldn’t tell you why. I’ll try your solution next time.
February 9th, 2009 at 12:06 pm
I have the same problem and I almost gave up to fix it. Thanks for 1000 times. I appreciate it and you made my day.
February 9th, 2009 at 12:31 pm
Thanks for the trick!
February 9th, 2009 at 12:37 pm
Wow, great tip! Thanks.
February 12th, 2009 at 8:01 am
how to solve this problem for internet explorer http://jitendravyas.com/ie6.html
February 14th, 2009 at 9:24 pm
Thanks for the fast tip.
I spent around 8 hours trying to fix this thing.
Although I was trying to do it with a Javascript dynamic iframe and now I’ll do it with a div and with an AJAX call. Thanks to you.
Good and fast demo.
Thanks again.
February 16th, 2009 at 2:22 pm
Thanks for the tip! Saved me a ton of grief.
Great! Thanks, it works.
But this will not work in any other browser, since the content in the child div will then be (correctly) positioned behind the contents in the parent div!
Absolutely fantastic. Worked perfectly after trying other hacks with zero success. Many thanks!
This post made my day! My divs were all showing up fine in FF and Safari, but disappearing behind the parent div in IE. Thanks for posting and sharing.
The trick works because IE doesn’t allow elements to have a higher z-index than their parent element. It’s actually a reasonable restriction, if somewhat unneccessary (like Mozilla’s insistence that opacity always inherit).
You can sometimes get around this by taking advantage of the fact that absolutely positioned elements don’t care about their parents (though this can get inconvenient if you’re unfamiliar with your DOM in JS). Simply find a good element to position as relative, then set up independent elements and use the absolute positioning/z-index to put them where you want them.
Wow – brilliant! You’ve turned my day around from seemingly unending frustration to a successful and happy one. Thank you very much indeed for sharing this neat trick.
Thanks. I also noticed that if you have nested absolutely positioned elements this fix won’t work unless you put the higher z-index on the top most relatively positioned element. In other words don’t just put the higher z-index on the parent element, put it on the first parent that is positioned relatively.
Thanks for the advice. I had the same problem. It was not just as easy as changing a couple of the indexes, so I wrote a javascript to reindex the divs. All of my stuff was in divs, so it worked. See the code below:
function reIndex(){
forms = document.forms
zi = 2000;
cn = document.getElementsByTagName(‘div’);
for (n=0;n<cn.length;n++){
cn[n].style.zIndex=zi–
}
}
Thought this may help someone else.
Matt
I forgot to mention, you call this after everything has already loaded.
Thank you! Hours of work dropped to a couple of minutes of tweaking…
Unfortunately both my divs were children of the same element, so luckily:
@SteveG – thank you! Giving the second element a z-index:-1 worked
,
Honestly, can’t calculate the time i’ve wasted on this browser…
[...] Give the element (that should be behind) a z-index:-1 [...]
Really neat trick, cheers!
THANK YOU SO MUCH! SPENT 2 DAYS (16 HRS) TRYING TO FIX, THIS DID THE TRICK!
.andrew champ
man, thank you so much!!!
Wow, thanks a lot!
Thank you for this fix, this one worked for me! I have included it in my binder of potential workarounds for the IE z-index bug:
http://www.livebinders.com/play/play?id=1808
I had the same problem.. I added the z-index property to css of the main div and it work.
I am waiting for the day to stop working on IEs
Thanks.
I had the same problem. A menu that opens up and was hidden behind the main content window.
But adjusting z-index on any element did not help. I got it fixed however, my problem was that my parent element had overflow:hidden;
Watch out for that ![]()
THANK YOU!! life saver. ![]()
Thanks – this saved me a lot of time!
Thanks for the simple fix.
ThanKs!!
Thanks for the tip. I had to reconfigure my code just a touch to match your example, but it worked great.
after hours on end searching for a solution…
THANK YOU!!
may IE die a slow and painfull death
Just ran into this problem again, as usual. What Scott wrote earlier is correct – this only works if you are applying it to relative positioned elements – doing it on absolute positioned elements does not help! Stinking IE.
[...] j’ai trouvé la solution sur ce blog. J’ai résolu le problème en définissant un z-index le plus élevé sur #header. Ce qui [...]
Saved my bu++
Thanks
Thanks for this… sorted out my issue in an instant!
Thanks you so much.
Helped me on my Crewe United Football Club drop down menu.
September 3rd, 2009 at 5:14 am
thank you very much….
It’s help me lots…
September 5th, 2009 at 7:47 am
really this helps me a lot after 2 hours crazy-ing around with IE.
THANKS!
September 7th, 2009 at 8:06 am
Why the hell doesnt microsoft IE conform to CSS standards like all other browsers?
This goes to show that opensource is the way to go…
Long live firefox…
September 9th, 2009 at 2:44 am
I’ve been searching for this solution for such a long time.
Thank you very much!
September 12th, 2009 at 8:47 pm
Life saver, thankfully you were the first hit on Google.
You just got me out of a jam, thanks again
September 18th, 2009 at 5:58 am
Thanks very much…perfect.
September 18th, 2009 at 11:26 am
Keith was close when identifying the problem, but wrong.
The issue is that when you give a z-index to a container, it restarts the z-indexing inside of it at 0, and the global-level z-index of everything inside the container becomes the same as the parent.
When you have a container without a z-index, it gets a value of ‘auto’ and *shouldn’t* affect the z-indexing of anything inside of it.
However when internet explorer finds a relatively positioned element with a z-index of ‘auto’, it treats it like it has z-index of ‘zero’, thus restarting the z-indexing inside that container. From that point, everything inside that container has a global-level z-index value of 0.
Your solution worked because the menu aquired a global-level z-index that was the same as its container, which was in turn higher than the image of the car.
To illustrate this, you could give the car a z-index of 500, and change the ‘1000′ z-index with a value of ‘1′ and it would still work.
September 29th, 2009 at 10:12 am
[...] This article helped me how to solve IE z-index problem. There is a good comment at the end as well.Title is called Squish the Internet Explorer Z-Index Bug and written by Brenelz Web Solutions.http://www.brenelz.com/blog/2009/02/03/squish-the-internet-explorer-z-index-bug/ [...]
I spent a few hours on this last night and was ready to lose my mind when I found your tip. Other developers have posted complex javascript solutions online, but this solved my problem quickly. Thanks!!
that’s so simple that makes me feel stupid for wasting so much time trying to fix it.
thank you very much ![]()
This was tweaking me off big-time. Thank you so much for the fix. Your solution was the simplest one for this ridiculous problem. Thanks again!
November 4th, 2009 at 12:26 am
Awesomesauce. I was about to kill someone before finding this fix. You rock it.
November 10th, 2009 at 3:55 am
Hi,
it’s nice solution but not worked for me.
I have same case with menu,but under menu I have tabs. The issue with relative z-index -1 make tabs unavailable.
Finally I did my solution with Jquery and relative position:
jQuery().ready(function(){
$(".slidemenu").hover(
function(e) {
$('#neg_position').css("z-index","-1").css("position","relative");
},
function() {
$('#neg_position').css("z-index","").css("position","");
}
).mousemove(
function(e) {
$('#neg_position').css("z-index","-1").css("position","relative");
}
);
});
slidemenu is container of my menu,neg_position my tabs container
I hope it help to somebody.
November 10th, 2009 at 7:46 pm
[...] But giving a higher z-index to the menu didn’t made it appear on top of the div below it. This post got the solution: the enclosing element of the menu needs a higher z-index than the actual menu. It [...]
November 18th, 2009 at 9:02 am
Just wanted to say thank you. I was struggling with this bug for a while until I found your post. Cheers.
November 24th, 2009 at 6:41 pm
Wow … I spent a couple hours today tryin’ to deal with this same issue. Apparently, not just the parent needs an updated z-index, but so do all the parents! Right up to the HTML tag.
Thank you for this fix! You saved me hours and hours of time.
November 26th, 2009 at 4:54 am
Hey, this is great, works like a charm!
Thanks for the easy fix
thanks mate, it saved me a lot of time~!
I cannot seem to get this to work for this page: http://yogasports.biz
Can anyone help?
The dropdowns appear behind the flash animation
Worked perfectly. Thank you!
Alina,
Try making your Flash transparent. Should fix the problem.
In addition to what Ricky said, IE always assigns a global z-index of 0 no matter whether the element is relatively or statically positioned whenever its z-index is not specified.
So, the workaround would be to set a higher z-index of the topmost parent element (immediately inside body) containing the menu.
thank you
December 9th, 2009 at 11:15 am
dev, you’re right, but it is only on relative & absolutely positioned elements. If you remove the position: relative or position: absolute from the parent, the problem goes away. However this is rarely an option that is available.
December 10th, 2009 at 3:15 am
thanks a lot…saved my day ![]()
December 11th, 2009 at 8:12 am
great tip! now just to squash IE…
December 15th, 2009 at 1:56 pm
saved my time! thanks ![]()
December 15th, 2009 at 9:07 pm
Thank you so much, that just saved me so much time!
December 16th, 2009 at 3:31 pm
You da man. Thanks!
December 21st, 2009 at 3:28 am
[...] figure IE inconsistencies like the double margin bug, png fix and z-index issue all to be common knowledge amongst web developers and designers. But why not this one? Surely the [...]
December 29th, 2009 at 1:34 pm
Saved my bacon. Thanks! (I hate ie7)
December 29th, 2009 at 2:06 pm
Thanks! This helped a lot. Also, thanks for the link to the quirksmode page.
Thank you, Thank you, Thank you.
Scott – you are genious! Excatly what i needed here!
Thanks mate, solved my problem
Good trick – unfortunately it doesn’t always solve the problem, especially with javascript and flash elements.
Instead you can stack the parent elements and use position:relative together with z-index. That stacks correctly in all IE versions.
Thanks a lot!
This really helped us out. Time for IE7 itself to be squished! ![]()
January 15th, 2010 at 12:06 pm
I think I love you, man ![]()
Thank you so much, life saver, been struggling with this for ages now. Your solution worked, so quick & easy.
Thank you…
January 19th, 2010 at 10:50 pm
The plague of my existence, squished!!!
There’s 2 days of my life I won’t get back…
So quick, so easy, so works in every browser. Thanks!
January 21st, 2010 at 12:45 am
Thanks heaps, life saver ![]()
Thanks Bro… its really work.. ![]()
Keep it up bro..
…
This solve my problem. Thanks a lot!
[...] Map due to IE not co-operating when I put a drop-down menu on the same page. This article from Brenelz Web Solutions saved the [...]
Just wanted to say thanks for this tip. Its so simple but really works.
Thank you.
Colby Wright
February 5th, 2010 at 12:50 am
I am going crazy here. Where do I actually put this code? In the body html or in some js file? I have no idea where to put the code and I have tried everything but the menu still displays behind the graphic. Please I need help
Twitter
@ChuckMeMondays well thats a good thing right? #controversyforthebetter
RSS Feed
Keep up with all of our updates by subscribing to our RSS feed!
FaceBook
Join our group on Facebook and become a fan of us!