css

z-index in Internet Explorer 7 (IE7)

z-index.gif

This is going to be a short, but sweet blog post that I thought everyone should know. Have you ever run into a problem where IE7 just won't listen to a style where you are trying to change the z-index of an image or list item?
Well try this quick fix.

If you are targeting an element like the following example:


#page ul li.button {
z-index:4;
}

And you are not getting the results you expect in IE7 try adding the position:relative; to the element. 9 times out of 10 it seems to resolve my z-index problems.


#page ul li.button {
position:relative;
z-index:4;
}

Happy styling!

position:absolute?

What if you want to put a z-index on an object with position:absolute? That works in FF but not in IE7..., the containing div is set to position:relative...

that's not a trick

That's not a trick... it's a w3c requirement for setting z-index. You need to set a position as well.. whether it be relative, absolute, static... it doesn't matter. It's one of the few things IE does right and FF does wrong.

yes!

works like a charm! thanks man

with ff and others

you will need a hack or some kind for this as it seems to work for ie7 but will break other browser layout.

Thank you!

Thank you very much for that tip, Shawn!