Can I set background image and opacity in the same property?

后端 未结 14 2227
南笙
南笙 2020-11-22 07:58

I can see in CSS references how to set image transparency and how to set a background image. But how can I combine these two in order to set a transparent background image?<

14条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 08:30

    I have used the answer of @Dan Eastwell and it works very well. The code is similar to his code but with some additions.

    .granddata {
        position: relative;
        margin-left :0.5%;
        margin-right :0.5%;
    }
    .granddata:after {
        content : "";
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        background-image: url("/Images/blabla.jpg");
        width: 100%;
        height: 100%;
        opacity: 0.2;
        z-index: -1;
        background-repeat: no-repeat;
        background-position: center;
        background-attachment:fixed;
    }
    

提交回复
热议问题