Is it possible to use calc()
function in CSS to manipulate hexadecimal color value?
In following CSS snippet I would like to use --enable
variable to switch between two hexadecimal color values for background-color
property of the MyBtnStyle: --enable-color
and --disable-color
.
It was possible to accomplish this when using rgb(r,g,b)
color format where each color component was computed using calc()
, but I would prefer to directly switch between hexadecimal color values.
:root {
--enable: 0;
--disable-color: #ff0000;
--disable-r: 255;
--disable-g: 0;
--disable-b: 0;
--enable-color: #00ff00;
--enable-r: 0;
--enable-g: 255;
--enable-b: 0;
}
.MyBtnStyle {
width: 100%;
height: 100%;
text-align: center;
border: 2px;
margin: 1px 1px;
color: black;
padding: 1px 1px;
background-color: calc(var(--enable-color)*var(--enable) + var(--disable-color)*(1 - var(--enable)));
}
/* this works */
/* rgb( calc(var(--enable-r)*var(--enable) + var(--disable-r)*(1 - var(--enable)) ),
calc(var(--enable-g)*var(--enable) + var(--disable-g)*(1 - var(--enable)) ),
calc(var(--enable-b)*var(--enable) + var(--disable-b)*(1 - var(--enable)) )) */