Opacitator
mix-blend-mode works for some browsers, but we found that it causes performance problems in Chrome, I have no idea why.
The designer from my team came up with this ingenious hack where you create a layer that is mostly transparent, but when it is superimposed on a white background, its color will match the color of the surrounding background.
The way this "magic" color is found; it is a calculation of how dark each color axis should be for the degree of opacity removal. The formula for this is 255 - ( 255 - x )/opacity . The problem is this: if the opacity is set too low, the formula gives you negative numbers (which cannot be used). If the opacity is too high, you will get some colors on non-white areas of your image.
Initially, we used a spreadsheet that would do the calculations, and by manual trial and error we found that the color is Goldilox.
As soon as we started using sass, I realized that this can be done using binary search. So I created a sass function that does all the work for us.
Check this out on sassmeister . Pass your background color to the opacitator function on line 56 of the sass code. and use the generated rgba color in the div (or pseudo-element) to overlay the image.
I also created a working example on codepen .
dovidweisz
source share