tags:

views:

497

answers:

4

I have 2 nested css elements. I need to get the parent to be on top, that is, above in z-axis, of the child element. Just setting z-index is not sufficient. How do I do this? Thanks.

http://jsbin.com/ovafo/edit

Edit: I can't set a negative z-index on the child, that'll set it to below the page container on my actual page. Is this the only method?

Edit2: Updated example to set both on position:absolute;

+4  A: 

Set a negative z-index for the child, and remove the one set on the parent.

http://jsbin.com/omazi/edit

Alan Haggai Alavi
Thanks, but I can't set a negative z-index on the child, that'll set it to below the page container on my actual page. Is this the only method?
Jourkey
May be you can experiment by setting z-index to other elements in the page and finally get the order in which you want them to be displayed.
Alan Haggai Alavi
As a rule of thumb, don't use z-index on your layout. Use it only for very specific scenarios like in this case and you will find it easier to manage.
Jaryl
+1  A: 

You would need to use position:relative or position:absolute on both the parent and child to use z-index.

nimbupani
Thanks for that, I updated the example, doesn't seem to help.
Jourkey
sorry, I didnt see the full nature of your request. you can definitely NOT set the child element behind the parent. You can only do so for sibling elements.
nimbupani
A: 

Parent wraps child. How would parent ever sit on top of it? Set child to display:none if you don't want to display it.

BalusC
OK, it's enough for me to know it can't be done. Thanks.
Jourkey
A: 

Since your divs are position:absolute, they're not really nested as far as position is concerned. On your jsbin page I switched the order of the divs in the HTML to:

<div class="child"><div class="parent"></div></div>

and the red box covered the blue box, which I think is what you're looking for.

carillonator