不确定这是否可能以及如何,但我尝试在我的代码中使用元素的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>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud) 我想知道是否有可能让背景图像在某个div中的所有html img之上(就像一种掩码)
我试过了:
#content img{
position:relative;
background-image:url('./images/image-mask-2.png');
z-index:100;
}
Run Code Online (Sandbox Code Playgroud)