Positioning and z-index in IE

Using absolute positioning to hide and show a nested list is one of the better ways to create a dropdown menu, and it can almost be done using only CSS. IE6 needs a little javascript help to respect the :hover pseudo-class. The Sons of Suckerfish will help you there.

Now you have your perfect semantic validating SEO friendly nested list in order to make the drop-down menu the client wants. The CSS is in place and the dummy you’ve thrown up works.
But when you implement it into the site the drop-down partly hides behind the content further down. Offcourse – it has an higher z-index. Easy fix. But then the juggernaut IE comes along and crashes the party.

In all IE, any element that has position:relative and haslayout=true
forms a stacking context. This is not correct, it would need to have a
z-index to act as a stacking context.

Assume you have two stacking contexts:

  • B follows A.
  • B is higher in the stack, nearest to the user.


No matter what z-index you choose for it, a child A-x will never leave
its stacking context A.

A. A-1, A-2, A-3 ….

No child of A will ever be higher in the stack than B.

A real life example

Stacking context before

In my case I had a #header which erroneously formed such a stacking context,
because of

#header {position:relative; width: 920px;} /* haslayout = true */

And there is a regular stacking context following:

#main {position:relative; z-index: 1}



No matter what z-index I chose for it, a child (#menu) of #header would never
leave its stacking context #header.

#header #menu

The #menu inside of #header would be painted over by #main. And even if
#main is transparent, the drop down #menu will loose mouse focus and

The solution

What it finally came down to was to apply z-index: 2 to #header, to
have the entire #header higher in the stack, nearer to the user, than

Stacking context

Thank you:

I could have never done this without the help of Ingo Chao and the ever useful css-discuss list.

About these ads

3 responses to “Positioning and z-index in IE

  1. I was wondering, do you had any more blogs?

  2. Nope, just this one. It keeps me busy enough.

  3. Pingback: hollyheisey.com » Blog Archive » Some Help With IE Bugs