Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make child element higher z-index than parent? [duplicate]

Tags:

css

z-index

Suppose I have this code:

<div class="parent">     <div class="child">         Hello world     </div> </div>  <div class="wholePage"></div> 

This jsFiddle: http://jsfiddle.net/ZjXMR/

Now, I need to have<div class="child"> in above of <div class="wholePage"> but in the jsFiddle you can see that the child element rendered before <div class="wholePage">.

If you remove the parent class position or z-index, everything works fine. This is the correct behavior that I need: http://jsfiddle.net/ZjXMR/1/

How can I do that with z-index and without removing anything from page?

like image 848
Afshin Mehrabani Avatar asked Apr 17 '13 10:04

Afshin Mehrabani


People also ask

Can a child have higher z index than parent?

This is impossible as a child's z-index is set to the same stacking index as its parent.

Do child elements inherit Z index?

No, it isn't inherited.

How do you make a child DIV element wider than the parent DIV?

In this case, we set the child element's width to be 100% of the viewport width by using a percentage viewport unit (vw), then, we move it to the left side (by the distance of the viewport's half, minus 50% of the width of the parent element) with the left property.


1 Answers

This is impossible as a child's z-index is set to the same stacking index as its parent.

You have already solved the problem by removing the z-index from the parent, keep it like this or make the element a sibling instead of a child.

like image 113
Kyle Avatar answered Sep 29 '22 08:09

Kyle