The Blog

IE “phone-book”

This one’s very bad one.

If you load up this page you’ll see a layout which has this structure:

example layout structure - gecko/khtml/opera display
  • relatively positioned list, id=”topnav”
  • static div below it
  • relatively positioned div, id=”content”, which has some example content

In Mozilla, it apears as you (or at least I) would expect – menu goes above the remaining text. In IE, it goes below the Help section text, for reasons I thought had something to do with float + position:relative combo.

example layout structure - IE display

Real reason was this: when you define block element to be position:relative (content in my test case) this will not only reset the coordinate system for its child elements, it will also create a whole new dimension for z-index. Thus, an absolutely positioned element in the body with z-index: 400 (or I assume any other number) will go *below* the absolutely positioned (or floated) block with z-index:1 in the content div.

Update: I’m wrong here: new z-index context (dimension) will be created only if z-index is non-auto. Declaring only position:relative will not create new context.

This goes on for as much relative divs you have. In my example, content of 2nd relative block element was showing above the content of the 1st relatively positioned.

I named it after Michael Landis’s explanation on css-discuss list, who suggested that each pos:rel marks the beggining of the new set of pages, all above the previous ones.

Solution?
Whatever you come up with. I chose not to use position: relative in the dynamic drop-down menu I was building (and encountered this).

And now, the funniest thing: IE’s behavior is by-the-book (thanks to Big John who pointed this out to me). Yes, this is how W3C specs say it must work. I must admitt that I can’t see when would one want this to behave in this manner. But I can also just be grumdgy.

Bah…every day you learn something new.

Banca

Banca

Beautiful and functional currency converter, supports just about any currency in the world.

Go Couch to 5k

Go Couch to 5k

The most popular starter running program in beautiful feature-rich app (GPS tracking, charts, detailed history etc)

Quickie to do

Quickie to do

The fastest short-term task-list / check-list app on the App Store. Really.

Guerrilla Cardio

Guerrilla Cardio

The most challenging high-impulse interval training in the world.

Run Mate

Run Mate

A versatile running coach app, with unlimited number of running programs. Perfect for casual runners.

2 Comments

Feel free to chime in, looking forward to it. Leave a Comment

  1. You can solve this issue by having the <li> “position:static” and the <a> “position:relative”. This does of course of change the origin of the submenu, and therefore requires the menu positioning to be done in javascript. Works though..

  2. Screwtape says:

    I note that the CSS2.1 spec says “Other stacking contexts are generated by any positioned element (including relatively positioned elements) having a computed value of ‘z-index’ other than ‘auto’” (http://www.w3.org/TR/CSS21/visuren.html#q30) which leads me to believe that ordinary elements with position: relative should *not* establish new stacking contexts, which means that although IE adheres to the murky text of CSS2, Gecko adheres to the clearer intent of CSS2.1.

    The poor IE team, they can’t seem to get anything right!

Comments are now closed for this article.