tags:

views:

70

answers:

2

Sample of the problem

Let there be 3 divs.

<div id="div1"><div id="div2"></div></div>
<div id="div3" />

If div2 has a higher z-index than div3 but div1 has a lower z-index than div3, then div2 will be shown below div3.

Is there any way to have div2 be above div3 without changing the z-index of div1 or making div2 a sibling of div1/div3?

+1  A: 

Unfortunately no. As long as and div1 has a higher z-index than div3, everything in div1 will appear above div3.

CrazyJugglerDrummer
in this example, div1 has a z-index that is *lower* than in div3
JohnnyYen
+1  A: 

Using the html you gave above:

#div1{
    width: 200px;
    height: 200px;
    z-index: 30;
    border: 1px solid black;
}
#div2{
    width: 150px;
    height: 150px;
    z-index: 35;
    border: 1px solid black;
    position: relative;
    top: 70px;
    left: 10px;
    background-color: red;
}
#div3{
    width: 200px;
    height: 200px;
    z-index: 32;
    border: 1px solid black;
    background-color: lime;
    position: relative;
    top: -30px;
    left: 40px;
}

This seems to work, at least on FF and IE 8

Kristoffer S Hansen
What do you mean by work? I would like to see div2 being shown above div3, but this doesn't happen in Chrome4, FF3.5 or IE8.
JohnnyYen
Full code at github: http://gist.github.com/292846
Kristoffer S Hansen
Your suggestion works perfectly. Unfortunately we underestimated the problem we were having. But this is already a topic of another question. Thanks.
JohnnyYen