user931319
user931319

Reputation: 47

Div overlapping

I am trying to create two <div>'s that overlap. The only problem is that the second <div> is in front of the first <div> and it has to be the other way around. I've tried setting the z-index of the first <div> to 1 but it still does not work.

Here is my code:

 #content{
background-color:pink;  
overflow:auto;
position:relative;

}
#content_1{

width:400px;
height:1600px;
background-color:#000099;
margin:0 auto;
z-index:1;
}
nav{

width:300px;
height:500px;
background-color:yellow;


position:absolute;
top:0;  
right:200px;
z-index:0;

}

<div id="container">

  <header> </header>

   <div id="content">
       <div id="content_1"></div>
       <nav></nav>
 </div>

  <footer></footer>
 </div>

How can I make the first div overlap the second?

Upvotes: 2

Views: 3368

Answers (2)

Bosworth99
Bosworth99

Reputation: 4234

z-indexing works when both elements share the same stacking context, both are positioned (relative or absolute), and both have a z-index attribute applied. In this case you've only applied the positioning and z indexing attributes to one.

Upvotes: 2

GuyFromOverThere
GuyFromOverThere

Reputation: 471

add position absolute to content_1 or add position relative

Upvotes: 1

Related Questions