Setting opacity to background-image and background-colour

前端 未结 2 1779
说谎
说谎 2021-01-23 21:03

Is it possible to keep a background image 100% opacity and make the background-colour 50% opacity?

.smallIcons{
    background-color: #f00;
    opacity: 0.5; //          


        
2条回答
  •  一向
    一向 (楼主)
    2021-01-23 21:31

    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.

提交回复
热议问题