我基本上希望始终在最前面放置一个居中的图像(“drob”div),如果它们重叠,则其他 div 位于其后面。
代码如下:
body {
background-image:url('background.jpg');
}
#container {
width: 1040px;
height: 768px;
margin: 0 0 0 75px;
}
#navbar {
float: right;
height: auto;
width: 150px;
margin: 0 0 0 10px;
color: #FF0;
list-style: none;
}
#note {
width: auto;
height: auto;
float: left;
margin: 20px 0 0 -110px;
}
#drob {
height: auto;
width: auto;
float: left;
margin: 50px 0 0 -20px;
}
#gallery {
float: left;
width: 675px;
height: auto;
margin: -125px 0 0 -20px;
}
#gallery img {
float: left;
margin: 0 0 0 5px;
}
#video {
height: auto;
width: auto;
float: left;
margin: 150px 0 0 -20px;
}
<div id="container">
<div id="navbar">
<ul>
<li>Home</li>
<li>About Denard</li>
<li>Stats</li>
<li>Media</li>
</ul>
</div>
<div id="video">
<iframe width="450" height="265" src="http://www.youtube.com/embed/ZmmCAI8U_Vc"
frameborder="0" allowfullscreen></iframe>
</div>
<div id="drob">
<img src="images/drob.png" height="560" width="404" alt="Denard Robinson" />
</div>
<div id="note">
<a href="#"><img src="images/note.png" height="464" width="331" alt="note" /></a>
</div>
<div id="gallery">
<img src="denard1.jpg" height="145" width="215" alt="denard1" />
<img src="denard2.jpg" height="145" width="215" alt="denard2" />
<img src="denard3.jpg" height="145" width="215" alt="denard3" />
</div>
</div>
</body>
最佳答案
您需要设置重叠 div 的 z-index。
具有较低 z-index 的 div 将位于具有较高索引的 div 之后。
您可以在 http://reference.sitepoint.com/css/z-index 找到更多关于 z-index 的信息
关于html - 如何将一个 div 放在另一个 div 之上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7424353/