Why is the CSS z-index being ignored in position relative using background cover image?


Overview: I have a CSS3 pure navigation system on top of my page. I have a footer/copyright on bottom.

In the middle, I want a background image (parchment) cover, then on top of that parchment, I want a white layer for text with a left column and a right column. I can't seem to make it work using the relative position as my z-index doesn't seem to be working. If I put position "fixed", I can't use the right browser scroll anymore to go down. If I use position "absolute", then the background is right and the content on top is ok, but my navigation footer disappears. If I use position "relative", my navigation system is fine but the background doesn't show up anymore. It is ignoring the z-index....

The weird thing is I am using expression web 4 and it looks correct there...it just doesn't look correct on the web.

This is my site html to reproduce what I am seeing.

<!-- #BeginEditable "content" -->
<div id="page_content_back">
    <div id="column_left">

        <p>We are the best-Trust us</p>

    <div id="column_right">
<!-- #EndEditable -->

This is my css

#page_content_back {
position: relative;
background-size: cover; 
z-index: 1;
width: 100%;
margin: auto;
padding: 0;
border-top-width: 1px;
border-top-style: solid;
border-top-color: #CCAA77;
#column_left {
position: relative;
margin: 0 50px;
padding: 0 2%;
z-index: 2;
top: 0px;
background-color: #fff;
float: left;
width: 65%;
height: 100%;   
color: #393939;
#column_right {
position: absolute;
z-index: 3;
float: right;
right: 50px;
top: 370px;
width: 20%;
height: 100%;
margin: 0;
padding: 10px;
background-color: #fff;
Problem courtesy of: Michael Barber


Okay, the problem is your div#column_left. It has a float: left property. Floating an element takes it out of the flow, so there's nothing within the div#page_content_back to give it any height. Remove that float: left property from the inner div and you'll see the image appear behind it. From there, you can add other elements after that nested div and the image will expand to encapsulate the new element. That said, if you use float or position: absolute, you're removing the element from the flow and that background image won't respond to its presence as a result.

Solution courtesy of: Gray Spectrum


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.