Pat*_*ell 79 css sass rgba compass-sass
这可能是指南针101,但是有没有人写过mixin来设置颜色的alpha值?理想情况下,我希望mixin采用任何形式的颜色定义,并应用透明度:
@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);
Run Code Online (Sandbox Code Playgroud)
max*_*tty 170
设置颜色的不透明度.
例子:
rgba(#102030,0.5)=> rgba(16,32,48,0.5)
rgba(蓝色,0.2)=> rgba(0,0,255,0.2)参数:
(Color)color
(Number)alpha - 介于0和1之间的数字返回:(
颜色)
码:
rgba(#ff0000, 0.5); // Output is rgba(255,0,0,0.5);
Run Code Online (Sandbox Code Playgroud)
我使用rgbapng指南针插件
rgbapng是一个Compass插件,用于提供跨浏览器*兼容的RGBA支持.它的工作原理是为不支持RGBA的浏览器动态创建单像素alpha透明PNG.它使用纯Ruby ChunkyPNG库,从而实现轻松的安装和部署.
安装
gem install compass-rgbapng
Run Code Online (Sandbox Code Playgroud)
用法
@include rgba-background(rgba(0,0,0,0.75));
Run Code Online (Sandbox Code Playgroud)
编译为:
background: url('/images/rgbapng/000000bf.png?1282127952');
background: rgba(0, 0, 0, 0.75);
Run Code Online (Sandbox Code Playgroud)
小智 5
rgba函数不适用于没有透明度的颜色,它将再次返回十六进制。毕竟,这并不意味着要将十六进制转换为rgba,我们只是从十六进制中获利,尚不允许使用alpha(尚未)。
rgba(#fff, 1) // returns #fff
Run Code Online (Sandbox Code Playgroud)
因此,我做了一些小功能来构建rgb字符串。我现在不需要处理透明胶片。
@function toRGB ($color) {
@return "rgb(" + red($color) + ", " + green($color) + ", " + blue($color)+ ")";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52810 次 |
| 最近记录: |