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

后端 未结 8 1313
轮回少年
轮回少年 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:08

    None of the solutions worked for me. If everything else fails, get the picture to Photoshop and apply some effect. 5 minutes versus so much time on this...

    0 讨论(0)
  • 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

    <div> put your div content</div>
    
    0 讨论(0)
提交回复
热议问题