如何使用Less编译器将十六进制颜色转换为rgba? [英] How do I convert a hexadecimal color to rgba with the Less compiler?

查看:235
本文介绍了如何使用Less编译器将十六进制颜色转换为rgba?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

@color : #d14836;

.stripes span {
    -webkit-background-size: 30px 30px;
    -moz-background-size: 30px 30px;
    background-size: 30px 30px;
    background-image: -webkit-gradient(linear, left top, right bottom,
        color-stop(.25, rgba(209, 72, 54, 1)), color-stop(.25, transparent),
        color-stop(.5, transparent), color-stop(.5, rgba(209, 72, 54, 1)),
        color-stop(.75, rgba(209, 72, 54, 1)), color-stop(.75, transparent),
        to(transparent));

我需要将@color转换为rgba(209, 72, 54, 1).

所以我需要用一个Less函数替换我的代码中的rgba(209, 72, 54, 1),该函数根据我的@color变量生成一个rgba()值.

So I need to replace rgba(209, 72, 54, 1) in my code with a Less function that generates an rgba() value from my @color variable.

如何用Less做到这一点?

How can I do this with Less?

推荐答案

实际上,Less语言带有一个称为fade的嵌入式函数.您传递了一个颜色对象和一个绝对不透明度%(值越高表示透明度越低):

Actually, the Less language comes with an embedded function called fade. You pass a color object and the absolute opacity % (higher value means less transparent):

fade(@color, 50%);   // Return @color with 50% opacity in rgba

这篇关于如何使用Less编译器将十六进制颜色转换为rgba?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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