Skip to content Skip to sidebar Skip to footer

Setting Opacity To Background-image And Background-colour

Is it possible to keep a background image 100% opacity and make the background-colour 50% opacity? .smallIcons{ background-color: #f00; opacity: 0.5; // 50% background

Solution 1:

Replacing opacity: 0.5; to background-color: rgba() Solved the issue:

   .smallIcons{
        background-color: rgba(255,0,0,0.5); // 50% background color
        background-image: url(../twiter.png); // 100% here
        background-repeat: no-repeat;
    }

In addition, If you're using sass you can assign your colour variable as below

   $col_var: #f00;
   .smallIcons{
        background-color: rgba($col_var, 0.5); // 50% background color
        background-image: url(../twiter.png); // 100% here
        background-repeat: no-repeat;
    }

Posted on behalf of future readers.


Solution 2:

Check this Css. Easiest way to do that

 .class {
   background:linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)
    ),url(image.jpg) no-repeat center top;
    }

Post a Comment for "Setting Opacity To Background-image And Background-colour"