How to use position-absolute and z-index with Internet Explorer 7 and nested containers

When you have a div-container which has the attribute position-absolute and you put a 2nd div-container inside (which has also a position-absolute attribute) it can happens that Internet Explorer 7 does not interpret this correct.

I had the problem, that the 2nd div-container (which is a fold-out CSS-menu) is larger than the sorrounding div. In IE 7 the CSS-menu lays, in the part outside the sorrounding container, behind those elements. But for a menu you aspect to be the first element in the hierarchy.

Those layer positions can be set using z-index in CSS. The higher the index, the higher the position of the element to users-view. So I set the z-index to a high value but in IE 7 nothing happened.

After trying a while I worked out a very easy solution. If you use for an element the position-absolute attribute it will be set out of the normal element-flow of the website and be positioned absolute to the given position. But IE 7 inherits the value from the parent-element (here the sorrounding div-container) which had no z-index.

So my solution is to give both, the surrounding and the inner div-container a z-index. The surrounding container gets (in my case) a higher z-index than the surrounding one and the problem is fixed! :)

The surrounding element is the YAML #topnav-element and the inner one is a div-container with list-items which are styled as a JS-free fully CSS-menu.

#topnav {
  overflow:visible;
  z-index:5;
  position:absolute;
  [...]
}

#inner_container {
  position:absolute;
  z-index:2;
  [...]
}

Related posts:

  1. overflow:auto – Internet Explorer 6 Bug
  2. How to code a jQuery slider menu
  3. How to … center a YAML Layout
  4. How to build a YAML fullscreen layout
  5. fight Internet Explorer 6 – reloaded
  6. CSS floating problems
  7. How to … integrate a YAML Menu to TYPO3
  8. CSS: center background image in Firefox & Co.

4 Responses to “How to use position-absolute and z-index with Internet Explorer 7 and nested containers”


  1. 1 Stefan

    It’s not work…

  2. 2 Abdullah Radwan

    Yes it’s not working for me either.

  3. 3 David

    Worked for me! Thanks so much!

  4. 4 Tom

    Worked like a charm for me. Thank you!

    Note that #topnav can also have position:relative and this will still work so long as the z-index is greater.

Leave a Reply

*