gpt4 book ai didi

ruby-on-rails - LESS CSS 预处理器 : Is there a way to map a single color to an rgb and rgba definition?

转载 作者:数据小太阳 更新时间:2023-10-29 06:58:58 24 4
gpt4 key购买 nike

我正在尝试在 CSS 预处理器 LESS 中编写一个 block ,它将执行以下操作:

@transparent_background(@color; @alpha: .8)
{
background: @color;
background: rgba(<color R value>, <color G value>, <color B value>, @alpha);
}

如果它是标准的十六进制定义(即#rrggbb),是否有任何方法可以从@color 中获取RGB 值?如果@color 是以其他方式定义的,有没有办法做到这一点?

编辑:解决方案

@transparent_background(@color; @alpha: .8)
{
background: @color;
background: @color + rgba(0, 0, 0, @alpha);
}

最佳答案

试试这个:

background: @color - rgba(0, 0, 0, 1.0) + rgba(0, 0, 0, @alpha);

减法将清除 @color 上的 alpha channel ,然后您只需将所需的 @alpha 添加到 alpha channel 。颜色具有全套操作符,并且在对两种颜色进行操作时,它们逐个组件地工作;颜色在内部存储为 RGBA 组件,因此这应该可以工作。此外,alpha channel 被标准化为在区间 [0, 1.0] 中,因此从 alpha channel 中减去 1.0 应该会清除它而不会导致任何问题。

我现在没有设置 CSS LESS,所以我无法检查,但这值得一试。

关于ruby-on-rails - LESS CSS 预处理器 : Is there a way to map a single color to an rgb and rgba definition?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4445238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com