:在绝对定位父级后面的伪元素之前

时间:2016-02-09 02:39:58

标签: html css pseudo-element

尝试在图像上添加阴影,我需要在父母后面放置:before或:之后才能让它工作。任何建议都会很棒。

.g-w-a {
    background-repeat: no-repeat;
    display: block;
    height: 240px;
    position: absolute;
    width: 160px;
    background-color: rgba(255, 0, 0, 0.5);
}

.g-w-a::after {
    background-color: rgba(0, 0, 0, 1);
    content: "";
    height: 20px;
    left: 40px;
    position: absolute;
    top: 210px;
    width: 50px;
    z-index: -2;
}

<div style="background-image: url(http://static.soliaonline.com/a/ae4329867a01e99b6b8ddbeb3d1c6f03.png)" class="g-w-a"><div class="t-shad">Rasen</div></div>

https://jsfiddle.net/bunzons9/1/

1 个答案:

答案 0 :(得分:1)

&#13;
&#13;
.g-w-a {
        background-repeat: no-repeat;
        display: block;
        position:relative;
        height: 240px;
        width: 160px;
        background-color: rgba(255, 0, 0, 0.5);
    }
    
    .g-w-a::after {
        background-color: rgba(0, 0, 0, 1);
        content: "";
        height: 240px;
        width: 160px;
        left: 10px;
        top: 10px;
        position: absolute;
        z-index: -2;
    }
&#13;
    
    <div style="background-image: url(http://static.soliaonline.com/a/082b36bc93e690cfda70e57e7eb86dac.png)" class="g-w-a"><div class="t-shad">Rasen</div></div>
&#13;
&#13;
&#13;