当前位置: 动力学知识库 > 问答 > 编程问答 >

css - Sass: Mix rgba(white,0.5) and solid background color

问题描述:

Need to calculate a final color for a font. In PSD the opacity of a font is 50%, color is #fff, background color is #7a4eb7. The result accordingly Photoshop should be #c4b5dd.

I guess there is no need in transparent color if background is always the same.

Can it be achieved with Sass?

Found an article on this topic but can't make it working:

http://thesassway.com/intermediate/mixins-for-semi-transparent-colors

网友答案:

Just resolved my question using second mixin from the article:

@mixin alpha-attribute($attribute, $color, $background) {
  $percent: alpha($color) * 100%;
  $opaque: opacify($color, 1);
  $solid-color: mix($opaque, $background, $percent);
  #{$attribute}: $solid-color;
}

Then you can use it as following:

// Mix font color rgba($white,0.5) and solid background
.text {
    @include alpha-attribute('color', rgba($white, 0.5), $studio);
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: