![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Perhaps someone else can learn from my mistake. As many developers may have learned, the "z-index" CSS property can (generally) only be applied to an element that is positioned; in other words, an element that has "position: absolute" defined. What is not explicitly spelled out (perhaps because it's common sense to some... not me) is that when elements are nested, the inner elements cannot be z-index'ed above the parent. div id="outer" style="position: absolute; top: 10; left: 0; z-index: 1" div id="inner" style="position: absolute; top: 0; left: 0; z-index: 2" p>You may think this would be on top...</p /div *** /div div id="biltong" style="position: absolute; top: 10; left: 0; z-index: 1" p>...but this is actually on top.</p /div In this example, the "inner" div's z-index of 2 only places it above any other div's you may define within the "outer" div (where the *** are). It's not placed above the "biltong" div, because the latter shares the same z-index as the "inner" div's parent. If you want the contents of the "inner" layer to be on top of everything else, its parent div "outer" needs to have a higher z-index than the other layers. Practical application: drop-down menu's that should appear above other layers. |
#3
| |||
| |||
|
|
What is not explicitly spelled out (perhaps because it's common sense to some... not me) is that when elements are nested, the inner elements cannot be z-index'ed above the parent. |
|
div id="outer" style="position: absolute; top: 10; left: 0; |
#4
| |||
| |||
|
|
In my understanding, there can only be one z-index 1. |
#5
| |||
| |||
|
|
As many developers may have learned, the "z-index" CSS property can (generally) only be applied to an element that is positioned; in other words, an element that has "position: absolute" defined. |
#6
| ||||||
| ||||||
|
|
Perhaps someone else can learn from my mistake. As many developers may have learned, the "z-index" CSS property can (generally) only be applied to an element that is positioned; in other words, an element that has "position: absolute" defined. What is not explicitly spelled out (perhaps because it's common sense to some... not me) is that when elements are nested, the inner elements cannot be z-index'ed above the parent. |
|
div id="outer" style="position: absolute; top: 10; |
|
z-index: 1" |
|
div id="inner" style="position: absolute; top: 0; left: 0; z-index: 2" |
|
p>You may think this would be on top...</p /div *** /div div id="biltong" style="position: absolute; top: 10; |
|
z-index: 1" p>...but this is actually on top.</p /div |
#7
| |||||
| |||||
|
|
Perhaps someone else can learn from my mistake. As many developers may have learned, the "z-index" CSS property can (generally) only be applied to an element that is positioned; in other words, an element that has "position: absolute" defined. |
|
What is not explicitly spelled out (perhaps because it's common sense to some... not me) is that when elements are nested, the inner elements cannot be z-index'ed above the parent. |
|
div id="outer" style="position: absolute; top: 10; left: 0; z-index: 1" div id="inner" style="position: absolute; top: 0; left: 0; z-index: 2" p>You may think this would be on top...</p /div *** /div div id="biltong" style="position: absolute; top: 10; left: 0; z-index: 1" p>...but this is actually on top.</p /div In this example, the "inner" div's z-index of 2 only places it above any other div's you may define within the "outer" div (where the *** are). |
|
It's not placed above the "biltong" div, because the latter shares the same z-index as the "inner" div's parent. |
|
If you want the contents of the "inner" layer to be on top of everything else, its parent div "outer" needs to have a higher z-index than the other layers. |
#8
| |||
| |||
|
|
ravi... (AT) gmail (DOT) com> wrote Perhaps someone else can learn from my mistake. As many developers may have learned, the "z-index" CSS property can (generally) only be applied to an element that is positioned; in other words, an element that has "position: absolute" defined.Really? http://www.w3.org/TR/CSS21/visuren.html#propdef-z-index "Other stacking contexts are generated by any positioned element (including relatively positioned elements) having a computed value of 'z-index' other than 'auto'." What is not explicitly spelled out (perhaps because it's common sense to some... not me) is that when elements are nested, the inner elements cannot be z-index'ed above the parent.Again, not true. RTMhttp://www.w3.org/TR/CSS21/visuren.html#propdef-z-index div id="outer" style="position: absolute; top: 10; left: 0; z-index: 1" div id="inner" style="position: absolute; top: 0; left: 0; z-index: 2" p>You may think this would be on top...</p /div *** /div div id="biltong" style="position: absolute; top: 10; left: 0; z-index: 1" p>...but this is actually on top.</p /div In this example, the "inner" div's z-index of 2 only places it above any other div's you may define within the "outer" div (where the *** are).not just divs, but anything in the outer (parent) div in this case. It's not placed above the "biltong" div, because the latter shares the same z-index as the "inner" div's parent. No, it shares the same -> stacking context <- because you set a z-index in the "outer" div. Did you try not setting a z-index on the outer div? RTM -> z-indext "stacking context" If you want the contents of the "inner" layer to be on top of everything else, its parent div "outer" needs to have a higher z-index than the other layers.Yes, if you've set a stacking context by setting a z-index on the parent div. That's how it's supposed to work. div id="outer" style="width:300px;position: absolute; top: 0; left: 0; background-color:red" div id="inner" style="width:200px;position: absolute; top: 15px; left: 15px; z-index: 2; background-color:lime" p>You may think this would be on top...(it is now)</p /div This is the parent of inner with no z-index. /div div id="biltong" style="width:100px;height:200px;position: absolute; top: 10px; left: 10px; z-index: 1; background-color:yellow" p>...but this is actually on top (not).</p /div RTM,RTM,RTM Rich |
![]() |
| Thread Tools | |
| Display Modes | |
| |