15 Jul

IE z-index bug

I was helping hostyle out with a puzzling z-index problem. An element he had given a z-index:100 was appearing below another element of z-index:0.

Finally, we managed to find the problem. It appears that if you have multiple position:relative elements in your code, then IE sets up separate Z layer contexts for each one, which ignore each other.

Here is an example of the bug. Note that Firefox displays it correctly, while IE does not.

Firefox screenshot IE screenshot

To solve it, try to keep the layered elements within the same position:relative context. Other than that, I’m not sure of a workaround.

24 thoughts on “IE z-index bug

  1. 3 dayzz of climbing up the wall and it may have been 3 months without the above tip. Client now removed from ceiling and nail marks plastered over. Fellow seekers will be pointed this way
    Many Many Thanks

  2. Why is it a problem to be 30? That sort of crap has resulted in IT professionals increasingly being unemployable well before middle age. What you sow you will reap.

  3. what? I think you misread my quote. I did not say that 30 was the age at which web developers suddenly forget how to code. It was merely a humourous reminder to myself that I am getting “old” (whatever that means, these days).

  4. Another workaround might be to set the z-index of all relative elements dynamicly when building the page. First element gets z-index 10000 or so, second gets 9990 and so on. A bit of a dirty trick, but if this can be achieved server side, at least you wont bother the client with it.

  5. You should set the z-index on the position:relative elements (and not on the absolute elements within it if you have any).

    Also note that when setting the z-index for a positioned element, a new z-order stack will be created for the child elements.

  6. Pingback: MahZeh.org » Blog Archive » Solutions to the IE z-index Bug: CSS

  7. Pingback: sunhwan » IE z-index Bug

  8. THANK YOU THANK YOU THANK YOU! I was splitting hairs over this stupid IE css error and I was about to give up until I found this. Problem solved.

  9. Let me join the choir of thankful people: I’ve been looking around the web, but this sentence explained it all: “It appears that if you have multiple position:relative elements in your code, then IE sets up separate Z layer contexts for each one, which ignore each other”.
    Thanks!

  10. thanks for this info — my easy workaround was to just wrap my elements in another div, positioned absolutely… i.e.

    <- this is to fix bug

    etc etc

    <– close ie7 fix div

    thx thx
    E

  11. Pingback: Superfish jQuery Menu IE z-index Bug | webdemar.com

  12. Pingback: Problema con bug de z-index en ie | Santa Pola

  13. Pingback: IE z-index bug with CSS dropdown menu | jonathan stegall

  14. Pingback: IE6 CSS bug: dropdown menu, z-index e elementi dei form. at My Notepad

  15. Pingback: Z-Index Issues in Internet Exploder « Vir2oso Design

Comments are closed.

%d bloggers like this: