Sass - Converting Hex to RGBa for background opacity

后端 未结 5 1837
迷失自我
迷失自我 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:11

    SASS has a built-in rgba() function to evaluate values.

    rgba($color, $alpha)
    

    E.g.

    rgba(#00aaff, 0.5) => rgba(0, 170, 255, 0.5)
    

    An example using your own variables:

    $my-color: #00aaff;
    $my-opacity: 0.5;
    
    .my-element {
      color: rgba($my-color, $my-opacity);
    }
    

    Outputs:

    .my-element {
      color: rgba(0, 170, 255, 0.5);
    }
    

提交回复
热议问题