I am using a rgba mixin like rgba('#2f305a',0.8), which works well, but I want to take it a step further. I need to make the color after opacity to appear the same color as if it were solid. I thought I saw a function that did this a while back, but can't seem to find it. Is there one our there or does anyone have one? I tried converting this and did this:
@function alphaCalc($desiredColour, $desiredAlpha, $backgroundColour: white) {
$r3: red($desiredColour);
$g3: green($desiredColour);
$b3: blue($desiredColour);
$r2: red($backgroundColour);
$g2: green($backgroundColour);
$b2: blue($backgroundColour);
$r1: ($r3 - $r2) / $desiredAlpha + $r2;
$g1: ($g3 - $g2) / $desiredAlpha + $g2;
$b1: ($b3 - $b2) / $desiredAlpha + $b2;
@return rgba($r1, $g1, $b1, $desiredAlpha);
}
.someEl {
background-color: alphaCalc(#2f305a,0.8);
}
Problem is I get an error: "$red: Color value -5 must be between 0 and 255 for 'rgba'"
r3 = 47; r2 = 255; r1 = (47-255)/0.8+255 = -5
So it seems like the formula is off or am I missing something here? Anybody have a solution?