css - 使 div 内的图像显示在其 div 背景后面

标签 css html z-index

我有一个 div,它的背景是部分透明的,带有水印。在 div 内部,我正在调用一个图像,但我希望该图像出现在 div 的背景后面,这样我就可以在图像上显示带水印的透明 div 背景。那可能吗?这是我无法使用的 CSS...

.artist-container {
background:url(images/artist-back.png);
    width:310px;
    height:376px;
    margin-left:-9px;
    z-index:331;
    position:relative;
}
.artist-container img {
    width:300px;
    height:300px;
    margin-left:5px;
    z-index:330;
    position:relative;
}

最佳答案

我使用一些 span 制作了一个小样本,它不会向您的文档添加任何语义内容,并且仍会保持图像的语义。

HTML:

<span class="cover_contain">
   <img src="http://i.imgur.com/hla4q.jpg" alt="[image]" width="128" height="128" />
   <span class="cover_image"></span>
</span>

CSS:

span.cover_contain {
    display: inline-block;
    position: relative;
}
span.cover_image {
    display: block;
    background: url('http://i.imgur.com/5BtFV.png') center center no-repeat;
    width: 128px;
    height: 128px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

jsFiddle Live Preview

关于css - 使 div 内的图像显示在其 div 背景后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9133204/

相关文章:

html - ng-grid 的列菜单的 z-index 问题

css - Z-index 不起作用

flash - IE-8 iframe 和 flash 对象忽略 z-index?

html - SVG Mask 不适用于插画师生成的 SVG(所有浏览器)

Jquery自定义警报框

html - 与 _Layout 相比,在 _LoginPartial 中设置 ActionLinks 的样式

html - 尽管使用显示 block ,但 margin 自动不被尊重

html - 媒体查询有问题,没有任何反应

html - CSS:定位不起作用

javascript - $ ('body' ).height() 变化不可预测