Change background image opacity

后端 未结 8 1455
-上瘾入骨i
-上瘾入骨i 2020-12-03 09:56

I have a div element with text blocks and a parent div in which I have set a background image. Now I want to reduce the opacity of the background image. Please suggest how I

8条回答
  •  不思量自难忘°
    2020-12-03 10:09

    You can't use transparency on background-images directly, but you can achieve this effect with something like this:

    http://jsfiddle.net/m4TgL/

    HTML:

    //my blog post

    CSS:

    .container {  position: relative; }
    
    .container:before {
        content: "";
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1;
        background-image: url('image.jpg');
       opacity: 0.5;
    }
    
    .content {
        position: relative; 
        z-index: 2;
    }​
    

提交回复
热议问题