Sass/Compass-将十六进制,RGB或命名的颜色转换为RGBA [英] Sass/Compass - Convert Hex, RGB, or Named Color to RGBA

查看:151
本文介绍了Sass/Compass-将十六进制,RGB或命名的颜色转换为RGBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是Compass 101,但是有人写过mixin来设置颜色的alpha值吗?理想情况下,我希望mixin采用任何形式的颜色定义并应用透明度:

This may be Compass 101, but has anyone written a mixin which sets the alpha value of a color? Ideally, I would like the mixin to take any form of color definition, and apply transparency:

@include set-alpha( red, 0.5 );          //prints rgba(255, 0, 0, 0.5);
@include set-alpha( #ff0000, 0.5 );      //prints rgba(255, 0, 0, 0.5);
@include set-alpha( rgb(255,0,0), 0.5 ); //prints rgba(255, 0, 0, 0.5);

推荐答案

使用 rgba函数

设置颜色的不透明度.

Sets the opacity of a color.

示例:

rgba(#102030,0.5)=> rgba(16、32、48、0.5)
rgba(blue,0.2)=> rgba(0,0,255,0.2)

rgba(#102030, 0.5) => rgba(16, 32, 48, 0.5)
rgba(blue, 0.2) => rgba(0, 0, 255, 0.2)

参数:
(颜色)颜色
(数字)alpha — 0到1之间的数字

Parameters:
(Color) color
(Number) alpha — A number between 0 and 1

返回:
(颜色)

Returns:
(Color)

代码:

rgba(#ff0000, 0.5); // Output is rgba(255,0,0,0.5);

这篇关于Sass/Compass-将十六进制,RGB或命名的颜色转换为RGBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆