首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将内部阴影添加到网格中的图像中?

如何将内部阴影添加到网格中的图像中?
EN

Stack Overflow用户
提问于 2014-08-12 07:37:37
回答 2查看 118关注 0票数 0

我的脑子疼,我不能让它起作用

我试图在这些盒子中添加内部阴影,使它们看起来与彼此的http://i.imgur.com/RlClNbh.png有点分离。

http://jsfiddle.net/96d7udd7/

我试过这个

代码语言:javascript
复制
img { 
  box-shadow: inset 0px 0px 10px rgba(0,0,0,0.5);
}

但是它只给了标志一个内在的阴影,而不是盒子里的图像。

这是该框的HTML

代码语言:javascript
复制
    <figure class="imgbox">
        <img src="img/1.jpg" height="400px" alt="image01"/>
        <figcaption style="background: rgb(53, 25, 10)">
            <h2><span>Coffe Name</span></h2>
            <a href="#">View more</a>
        </figcaption>           
    </figure>

和CSS

代码语言:javascript
复制
    figure.imgbox figcaption {
    box-shadow: inset 0px 0px 10px rgba(0,0,0,0.5);
    top: auto;
    bottom: 0;
    padding: 1em;
    height: 3.75em;
    background: #fff;
    color: #fff;
    -webkit-transition: -webkit-transform 0.35s;
    transition: transform 0.35s;
    -webkit-transform: translate3d(0,100%,0);
    transform: translate3d(0,100%,0);
}

figure.imgbox h2 {
    float: center;
}

figure.imgbox figcaption > span {
    float: center;
}

figure.imgbox p {
    position: absolute;
    bottom: 8em;
    padding: 2em;
    color: #fff;
    text-transform: none;
    font-size: 90%;
    opacity: 0;
    -webkit-transition: opacity 0.35s;
    transition: opacity 0.35s;
}

figure.imgbox h2,
figure.imgbox figcaption > span {
    -webkit-transition: -webkit-transform 0.35s;
    transition: transform 0.35s;
    -webkit-transform: translate3d(0,200%,0);
    transform: translate3d(0,200%,0);
}

figure.imgbox figcaption > span::before {
    display: inline-block;
    padding: 8px 10px;
    font-family: 'feathericons';
    speak: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.icon-eye::before {
    content: '\e000';
}

.icon-paper-clip::before {
    content: '\e001';
}

.icon-heart::before {
    content: '\e024';
}

figure.imgbox h2 {
    display: inline-block;
}

figure.imgbox:hover p {
    opacity: 1;
}

figure.imgbox:hover figcaption,
figure.imgbox:hover h2,
figure.imgbox:hover figcaption > span {
    -webkit-transform: translate3d(0,0,0);
    transform: translate3d(0,0,0);
}

figure.imgbox:hover h2 {
    -webkit-transition-delay: 0.05s;
    transition-delay: 0.05s;
}

figure.imgbox:hover figcaption > span:nth-child(4) {
    -webkit-transition-delay: 0.1s;
    transition-delay: 0.1s;
}

figure.imgbox:hover figcaption > span:nth-child(3) {
    -webkit-transition-delay: 0.15s;
    transition-delay: 0.15s;
}

figure.imgbox:hover figcaption > span:nth-child(2) {
    -webkit-transition-delay: 0.2s;
    transition-delay: 0.2s;
}

也许是电网出了问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-12 15:37:28

这与这样一个事实有关:当您将box-shadow应用于figure元素时,图像将位于其之上,并掩盖box-shadow。而且,据我所知,阴影不能直接应用于图像。

您可以使用:before规则来解决这个问题,也可以将图像作为background-image应用于figure,并将box-shadow应用于此元素。

因此,保持标记不变的:before的css如下:

代码语言:javascript
复制
.imgbox:before {
    content: "";
    height: 100%;
    width: 100%;
    position: absolute;
    box-shadow: inset 0px 0px 10px rgba(0, 0, 0, 1);
    z-index: 2;
}
.imgbox img {
    position:relative;
    z-index:1;
}
票数 1
EN

Stack Overflow用户

发布于 2014-08-12 08:56:22

你试过这样的东西吗?

代码语言:javascript
复制
<figure class="imgbox">
    <div class="ImgShadow"></div>
    <figcaption>
        <h2><span>Coffe Name</span></h2>
        <a href="#">View more</a>
    </figcaption>
</figure>

和CSS到ImgShadowclass:

代码语言:javascript
复制
.ImgShadow{
    background:url("http://i.imgur.com/DTL3hGL.jpg");  
    height: 100%;
    width: 100%;
    box-shadow: inset 10px 10px 10px #FF0000,inset -10px -10px 10px #FF0000;
    background-size:cover;
}

小提琴

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25258673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档