I would like to know if it possible to have a child element behind his parent element with z-index.
I would like to use the parent div as transparent color layer on top of his content.
I would like to know if it possible to have a child element behind his parent element with z-index.
I would like to use the parent div as transparent color layer on top of his content.
Why not? Sure you can, and it's easy:
z-index
of child to-1
;z-index
,opacity
,transforms
or whatelse generates a composite layer).(if the parent is used as a transparent layer, be sure to use a
background-image
or rgbabackground-color
: children inherit theopacity
of the parent)The short answer is Yes ;) There is an excellent article here that describes how you can use the stacking order of elements to allow the z-index to be negative in order to place an element behind it's parent.
http://philipwalton.com/articles/what-no-one-told-you-about-z-index/
You could just do it the other way and use the child as the overlay like this
HTML
CSS
Not possible, because each positioned element creates a stacking context.
Explanation 1, Explanation 2
While this wouldn't necessarily work in all browsers (especially older ones), the following has worked for me in the past:
I'm really only suggesting this as a last resort and would still prefer to use any technique other than this, although it might be ideal in your scenario.