2

I have a div that stand for the logo, and I have another div that stand for a slide show. The slide show div is under the logo div, and I want it to be under the it and behind it.

This is what I have:

HTML

  <div id="site-container">
    <div id="header-container">
    <div id="logo"></div>
    </div>
    
    <div id="slide"></div>
    </div>
   

CSS

#logo {
   background:url(img/logo.png) no-repeat left top;
   width:259px;
   height:147px;
   float:left;
}

#slide {
   background:url(img/slide.png) no-repeat left top;
   width:776px;
   height:437px;
   float:left;
}

I tried to use z position, but it turns to be something I dont want it to. Any why to make the logo div be a top layer without moving its correct position?

peterh
  • 11,875
  • 18
  • 85
  • 108
David Rose
  • 59
  • 1
  • 1
  • 4
  • 1
    possible duplicate of [How to overlay one div over another div](http://stackoverflow.com/questions/2941189/how-to-overlay-one-div-over-another-div) – Typo May 07 '15 at 15:32

5 Answers5

4

If you want it over top of the div, you have to use z-index. You have to convert your #logo and #slide to have a position attribute and z-index should be applied to the div whose position you want to move up or down.

Nitesh
  • 15,425
  • 4
  • 48
  • 60
4

Try the following: CSS

  #Behind{
    width:100%;
    background-color:orange;
    position: absolute;
    z-index: -1;
    padding:50px;
   }
  #TopOne{ 
    position: absolute;
    top:70px;
    left:50px;
    background-color:wheat;
    padding:20px; 
    }

and the htm simply

    <div id="Behind"></div>
    <div id="TopOne">This is Just Testing :)</div>

This is the JSFiddle link also JSFiddle

Adel
  • 1,468
  • 15
  • 18
3

The corrected css is,

 #logo {
   background:url(img/logo.png) no-repeat left top;
   width:259px;
   height:147px;
   float:left;
   position:absolute;
   z-index:1000;
}

#slide {
   background:url(img/slide.png) no-repeat left top;
   width:776px;
   height:437px;
   float:left;
   position:relative;
   z-index:500;
}

The position of the slide div is set as relative and logo div is set as absolute. So the logo is placed within the slide.

The value of z-index attribute decides which one is under.

Vinod VT
  • 6,946
  • 11
  • 51
  • 75
2

You are missing quite a few things to do that.

z-index will tell you what comes on top.

position needs to be absolute

And you may what to play with the margins...

user2032040
  • 101
  • 1
  • 4
1

i used these:

#logo {
   background:url(img/logo.png) no-repeat left top;
   width:259px;
   height:147px;
   float:left;
   position:absolute;
   z-index:1;
}

#slide {
   background:url(img/slide.png) no-repeat left top;
   width:776px;
   height:437px;
   float:left;
   position:relative;
}

and the slide show is now when it should be but the logo div float to the right while i need it to stay at the left side... sorry if you dont understand not sure about my english grammer lol

David Rose
  • 59
  • 1
  • 1
  • 4