html - css 图像蒙版覆盖

标签 html css xhtml overlay

我试图让透明的 png 框架图像悬停在 img 标签上,以在其上创建框架的外观。我尝试了多种不同的方法,但似乎都不起作用。

我使用的最新方法是http://www.cssbakery.com/2009/06/background-image.html这似乎也不起作用。

HTML

<div class="filler">
    <div class="filler-picture">
        <img src="../../media/img/test.jpg" alt="test" />
        <div class="filler-mask">&nbsp;</div>
    </div>
</div>

CSS

.filler {

    padding-left:20px;
    height:361px;
    width:559px;
    float:left;

}

.filler-mask {

    background: url('..img/filler.png') no-repeat;
    position: absolute;
    left:0; top:0;
    height:361px;
    width:559px;

}

.filler-picture {

    z-index: 0;
    background: url('..img/test.jpg') no-repeat;
    position: relative;
    height: 361px;
    width: 559px;
    display: block;

}

有谁知道为什么这不起作用。

最佳答案

你可以在具有不同 z-index 的填充图片下放置 2 个绝对 div

<div class="filler">
    <div class="filler-picture">
        <div class="filler-img">
            <img src="../../media/img/test.jpg" alt="test" />
        </div>
        <div class="filler-mask">
            <img src="../../media/img/filler.png" alt="filler" />
        </div>
    </div>
</div>

CSS

.filler-mask {
    position: absolute;
    left:0; top:0;
    height:361px;
    width:559px;
    z-index: 900;
}

.filler-img{
    position: absolute;
    left:0; top:0;
    height:361px;
    width:559px;
    z-index: 50;
}

您可以直接放置图像而不是使用图像作为背景,但图像不遵循 z-index,因此您必须将图像包装在 div 中。

关于html - css 图像蒙版覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3182683/

相关文章:

html - 为什么在 CSS 中从针对类更改为类型会导致不同的结果?

javascript - 旋转后保持div滚动位置

html - 缩放时 CSS "position: fixed"在移动设备上无法正常工作

jquery - 增加和减少jquery移动面板的宽度

css - 如何修复 IE 和 Chrome 中 ajax 弹出窗口层上的 YouTube flash 视频叠加问题?

html - 可以在 Outlook 中使用媒体查询吗

html - 忽略 css 中的最小宽度

php - 尝试将 PHP header 与 IFrame 一起使用

html - 基于 Css 的菜单,可将网站向下滑动

eclipse - 如何通过 Eclipse IDE 在 XHTML 中使用 Facelets 开发应用程序?