Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何在情感中将十六进制颜色转换为rgba_Css_Reactjs_Less_Emotion - Fatal编程技术网

Css 如何在情感中将十六进制颜色转换为rgba

Css 如何在情感中将十六进制颜色转换为rgba,css,reactjs,less,emotion,Css,Reactjs,Less,Emotion,我正在将我的应用程序的样式从较少转换为 在Less中,我的风格如下: @blue: #476882; background: rgba(red(@blue), green(@blue), blue(@blue), 0.5); 在转化为情感的过程中,我正在这样做: export const BLUE = '#476882' background: rgba(red(${BLUE}), green(${BLUE}), blue(${BLUE}), 0.5); 但是它不起作用 有什么建议可以让这

我正在将我的应用程序的样式从较少转换为

在Less中,我的风格如下:

@blue: #476882;
background: rgba(red(@blue), green(@blue), blue(@blue), 0.5);
在转化为情感的过程中,我正在这样做:

export const BLUE = '#476882'
background: rgba(red(${BLUE}), green(${BLUE}), blue(${BLUE}), 0.5);
但是它不起作用


有什么建议可以让这项功能发挥作用吗?

我找不到任何情感方法,但我个人用一个使用该软件包的实用函数解决了这个问题:


然后像这样使用它:
rgba(${rgba('#000',0.15)})

所有IDE都将此作为默认值或插件。试试这个,好运(颜色选择器)而不是这个:背景:rgba(红色(${BLUE})、绿色(${BLUE})、蓝色(${BLUE})、0.5;Try:背景:rgba(${RED},${GREEN},${BLUE},0.5);我有十六进制颜色
BLUE
,我不想创建3个变量
RED、GREEN和BLUE
Will
background color:${BLUE};不透明度:0.5
适合您?可能与
import hexRgb from 'hex-rgb';

export const rgba = (hex, alpha) => {
  const rgb = hexRgb(hex, { format: 'array' })
    .slice(0, -1)
    .join(',');
  return `${rgb},${alpha}`;
};