Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position absolute has greater z-index than position fixed

Tags:

css

I have a poblem with an element that is positioned relative. The problem is that I have a header with position fixed and content which is positioned relative. If I scroll down the content the element is put in front of the header. I tried with z-index but I just can't get it to work. I have put z-index:999 on header.

Here you can see my jsFiddle

Here is a picture: enter image description here

like image 666
dinodsaurus Avatar asked May 01 '13 08:05

dinodsaurus


1 Answers

The z-index on the relative positioned element should be lower than the z-index on the fixed position element. Here is a quick example:

HTML

<div id="fixed">Fixed Position</div>
<div id="relative">Relative Position</div>

CSS

body{
    height: 3000px;
}

#fixed{
    top: 0;
    height; 100px;
    background: green;
    width: 100%;
    position: fixed;
    z-index: 2;
}

#relative{
    position: relative;
    top: 100px;
    left: 50px;
    height: 100px;
    width: 100px;
    background: red;
    z-index: 1;
}

Working Example: http://jsfiddle.net/XZ4tM/1/

Fixing Your Example

The header styling has an issue, there are two colons :: proceeding the z-index properties value.

  .header{
        width:960px;
        background: #43484A;
        height:80px;
        position: fixed;
        top:0;
        z-index: 9999; /* Removed extra : here */
   }

Fixed Example http://jsfiddle.net/kUW66/2/

like image 181
Kevin Bowersox Avatar answered Oct 12 '22 09:10

Kevin Bowersox