如何在网格中的图像中添加内部阴影?

时间:2014-08-12 07:37:38

标签: jquery html5 css3 grid

我的大脑疼,我无法正常工作

我试图将内阴影添加到这些盒子中,这样它们看起来就像是彼此分开了 http://i.imgur.com/RlClNbh.png

http://jsfiddle.net/96d7udd7/

我试过这个

img { 
  box-shadow: inset 0px 0px 10px rgba(0,0,0,0.5);
}

但它只给徽标一个内阴影而不是框中的图像


这是方框的HTML

    <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

    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;
}

网格可能存在问题?

2 个答案:

答案 0 :(得分:1)

当您将box-shadow应用于figure元素时,图像会位于其顶部并遮挡box-shadow。另外,据我所知,阴影无法直接应用于图像。

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

:before的css,保持你的标记相同,因此:

.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 :(得分:0)

你有没有试过这样的东西

<figure class="imgbox">
    <div class="ImgShadow"></div>
    <figcaption>
        <h2><span>Coffe Name</span></h2>
        <a href="#">View more</a>
    </figcaption>
</figure>

CSS到ImgShadowclass:

.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;
}

jsfiddle