How to put div over another
hey guys i have 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?
thank you
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.
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.
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
链接地址: http://www.djcxy.com/p/75852.html下一篇: 如何把div放在另一个