不确定是否可能以及如何实现,但我尝试通过修改代码中元素的z-index来解决问题,但没有成功。
我有一个div元素,在css中设置了背景图像。在div内部,我还有其他元素,如div和img。我想让包含背景图像的主div保持在顶部,因为我希望该背景图像显示在其他元素上面(该背景图像具有我想要显示在包含在该div中的图像上方的一些圆角)。
HTML示例:
<div id="mainWrapperDivWithBGImage">
<div id="anotherDiv">
<!-- show this img behind the background image
of the #mainWrapperDivWithBGImage div -->
<img src="myLargeImage.jpg" />
</div>
</div>
示例CSS:
/* How can I make the bg image of this div show on top of other elements contained
Is this even possible? */
#mainWrapperDivWithBGImage {
background: url("myImageWithRoundedCorners.jpg") no-repeat scroll 0 0 transparent;
height: 248px;
margin: 0;
overflow: hidden;
padding: 3px 0 0 3px;
width: 996px;
}