Can I set an opacity only to the background image of a div?

后端 未结 8 1320
轮回少年
轮回少年 2020-11-22 11:09

Let\'s say I have

Hi there

I want to put a background-image and give it an opacit

8条回答
  •  心在旅途
    2020-11-22 12:09

    css

    div { 
        width: 200px;
        height: 200px;
        display: block;
        position: relative;
    }
    
    div::after {
        content: "";
        background: url(image.jpg); 
        opacity: 0.5;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        position: absolute;
        z-index: -1;
    }
    

    html

    put your div content

提交回复
热议问题