Sass - Converting Hex to RGBa for background opacity

后端 未结 5 1838
迷失自我
迷失自我 2020-12-12 09:40

I have the following Sass mixin, which is a half complete modification of an RGBa example:

@mixin ba         


        
5条回答
  •  死守一世寂寞
    2020-12-12 10:18

    If you need to mix colour from variable and alpha transparency, and with solutions that include rgba() function you get an error like

          background-color: rgba(#{$color}, 0.3);
                           ^
          $color: #002366 is not a color.
       ╷
       │       background-color: rgba(#{$color}, 0.3);
       │                         ^^^^^^^^^^^^^^^^^^^^
    
    

    Something like this might be useful.

    $meeting-room-colors: (
      Neumann: '#002366',
      Turing: '#FF0000',
      Lovelace: '#00BFFF',
      Shared: '#00FF00',
      Chilling: '#FF1493',
    );
    $color-alpha: EE;
    
    @each $name, $color in $meeting-room-colors {
    
      .#{$name} {
    
         background-color: #{$color}#{$color-alpha};
    
      }
    
    }
    

提交回复
热议问题