【发布时间】:2019-08-12 02:49:44
【问题描述】:
我想将十六进制颜色转换为 RGB,但在网上搜索我了解到我可以使用 SASS 但只能使用 RGBa。
所以考虑一下这段代码:
@mixin hex-rgba($hexcolor, $opacity) {
background-color: rgba($hexcolor, $opacity);
}
div {
@include hex-rgba(#333333, .3);
}
返回:
div {
background-color: rgba(51, 51, 51, 0.3);
}
但如果我将 alpha 设置为 1(或 100%),它会返回十六进制值:
div {
@include hex-rgba(#333333, 1);
}
div {
background-color: #333333;
}
即使 alpha 为 100%,我如何获得 rgba 值?
以某种方式
div {
background-color: rgba(51, 51, 51, 1);
}
已解决
@function rgb($hexcolor){
$red:red($hexcolor);
$green:green($hexcolor);
$blue:blue($hexcolor);
$alpha:alpha($hexcolor);
@return unquote("rgb(#{$red},#{$green},#{$blue})");
}
:root {
--color: #{rgb(#ffffff)};
}
【问题讨论】:
-
尝试百分比的更新代码
-
如果有人回答了您的问题,您应该接受他们的回答,而不是用解决方案更新问题。