CSS3图像帧边框z-index

时间:2012-09-26 19:58:14

标签: css3 border

我的图片有以下标记:

img.framed
{
    border-image: url('../images/design/frame.png') 40 40 40 40 stretch stretch;
    border-color: #f4be52; border-style: inset; border-width: 40px;
}

我得到了这个结果:

enter image description here

我不喜欢,框架内的图像会覆盖我框架的一部分。

如何修改代码以使图像显示超过

就像那样:

enter image description here

1 个答案:

答案 0 :(得分:3)

必须隐藏图像的某些部分才能创建您想要的内容。

创建包含图像的主div,以及另一个用于边框的div。

这个主div是相对定位,因此其中绝对定位的元素相对

将框架边框背景应用于子div,而不是图像。这个子div应该与图像的宽度和高度几乎相同,并且z-index比图像更多。此外,将其略微顶部和左侧放置成图像。

<div class="main">
    <div class="image-container">
    <!-- does not actually contain the image -->
    </div>
    <img src="some image"/>
</div>

JS Fiddle

我使用普通边框来显示重叠。绿色边框与图像的黄色bg重叠。

这是CSS:

.main {
    position: relative;
    top: 100px;
    left: 10%;
}
.image-container {
    position: absolute;
    left: -70px;
    top: -70px;
    border: 20px solid rgba(25,255,25, 0.5);
    z-index: 5;
    width: 230px;
    height: 330px;
    border-image: url('your frame link') 90 90 90 90 stretch stretch;
    border-color: #f4be52;
    border-style: inset;
    border-width: 86px;
}
img {
    position: absolute;
    background: #eaff77;
    width: 260px;
    height: 360px;
    z-index: 1;
}
.main:hover > img {
    z-index: 10;
}

<强>更新
我用真实的图像和适当的宽度和高度更新了小提琴。 Plz检查。
当您将鼠标悬停在图像上时,您会看到实际尺寸。这只是为了证明Frame实际上与图像重叠,这就是你想要的。