这可能是指南针101,但有谁写了一个mixin设置一个颜色的alpha值?理想情况下,我希望mixin采取任何形式的颜色定义,并应用透明度:
@include set-alpha( red,0.5 ); //prints rgba(255,0.5); @include set-alpha( #ff0000,0.5 ); //prints rgba(255,0.5); @include set-alpha( rgb(255,0),0.5 ); //prints rgba(255,0.5);
解决方法
使用
rgba
function built into Sass
Sets the opacity of a color.
Examples:
rgba(#102030,0.5) => rgba(16,32,48,0.5)
rgba(blue,0.2) => rgba(0,255,0.2)Parameters:
(Color) color
(Number) alpha — A number between 0 and 1Returns:
(Color)
码:
rgba(#ff0000,0.5); // Output is rgba(255,0.5);