HighDots Forums  

z-index not positioning properly?

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss z-index not positioning properly? in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ravidew@gmail.com
 
Posts: n/a

Default z-index not positioning properly? - 11-01-2006 , 01:11 PM






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.


Reply With Quote
  #2  
Old   
richard
 
Posts: n/a

Default Re: z-index not positioning properly? - 11-01-2006 , 01:52 PM







<ravidew (AT) gmail (DOT) com> wrote

Quote:
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.

In my understanding, there can only be one z-index 1.
That would be the one last implied, so your "But this is on top" would be
naturally.
In the second division, try the zindex 1 as a -1 rather than a +1 and see
what happens.



Reply With Quote
  #3  
Old   
Alexander Clauss
 
Posts: n/a

Default Re: z-index not positioning properly? - 11-01-2006 , 02:02 PM



<ravidew (AT) gmail (DOT) com> wrote:

Quote:
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.
It is "spelled out" explicitly. Just read the CSS specification
carefully, especially the section about the "stacking context":

<http://www.w3.org/TR/CSS21/visuren.html#z-index>


Quote:
div id="outer" style="position: absolute; top: 10; left: 0;
Please note that "top:10;" is invalid CSS code. Browser only accept this
in Quirks mode and will ingore this in standards compliant mode.

So you should correct this: "top: 10px;"

--
Alexander


Reply With Quote
  #4  
Old   
Bergamot
 
Posts: n/a

Default Re: z-index not positioning properly? - 11-01-2006 , 05:02 PM



richard wrote:
Quote:
In my understanding, there can only be one z-index 1.
Your understanding, as usual, is incorrect.

--
Berg


Reply With Quote
  #5  
Old   
Bergamot
 
Posts: n/a

Default Re: z-index not positioning properly? - 11-01-2006 , 05:03 PM



ravidew (AT) gmail (DOT) com wrote:
Quote:
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.
You've overlooked position:relative

--
Berg


Reply With Quote
  #6  
Old   
Gérard Talbot
 
Posts: n/a

Default Re: z-index not positioning properly? - 11-01-2006 , 05:34 PM



ravidew (AT) gmail (DOT) com wrote :
Quote:
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.
They are z-index-ed above the parent by default and this is covered by
the spec.

Quote:
div id="outer" style="position: absolute; top: 10;
Right here, you have a CSS parsing error: length values must have an unit.

CSS 1 and CSS 2.x specifications require that non-zero values must be
specified with a length unit; otherwise, the css declaration will be
ignored. Mozilla-based browsers, MSIE 6+, Opera 7+ and other W3C
standards-compliant browsers enforce such handling of parsing error.
CSS 1 Forward-compatible parsing
http://www.w3.org/TR/REC-CSS1#forwar...atible-parsing
CSS 2.1 Rules for handling parsing errors
http://www.w3.org/TR/CSS21/syndata.html#parsing-errors


left: 0;
Quote:
z-index: 1"
Defining z-index: 1 is required if there are other DHTML layers around,
otherwise, it takes the auto value.

Quote:
div id="inner" style="position: absolute; top: 0; left: 0;
z-index: 2"
There is no need to define a z-index here.

Quote:
p>You may think this would be on top...</p
/div
***
/div

div id="biltong" style="position: absolute; top: 10;

10 will be parsed and then will be ignored.

left: 0;
Quote:
z-index: 1"
p>...but this is actually on top.</p
/div
Gérard
--
remove blah to email me


Reply With Quote
  #7  
Old   
rh
 
Posts: n/a

Default Re: z-index not positioning properly? - 11-01-2006 , 07:08 PM



<ravidew (AT) gmail (DOT) com> wrote
Quote:
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'."

Quote:
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. RTM
http://www.w3.org/TR/CSS21/visuren.html#propdef-z-index

Quote:
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.

Quote:
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"

Quote:
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




Reply With Quote
  #8  
Old   
ravidew@gmail.com
 
Posts: n/a

Default Re: z-index not positioning properly? - 11-13-2006 , 03:40 PM



Yes, the "px" unit suffix was left off accidentally.

As for z-index itself: if anyone is confused about it, don't read my
first example. Find another.

I think it would be in the W3C's best interest (and undeniably also my
own) for them to create a XHTML/CSS/whatever reference site of their
own, one that:
- is concise enough to make finding the element/property/etc being
looked up easy
- is capable of expanding upon basic concepts with more details such as
examples, browser compatibility, known workarounds, etc.

Feel free to post any links to ref sites you use; my point is, the W3C
drafted this, why not spoil us with more tools?

On Nov 1, 7:08 pm, "rh" <disposable12... (AT) cableone (DOT) net> wrote:
Quote:
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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.