I have some content on a page that serves as a global background.
I put a sprite (div with background-image: url(...), changing frames by modifying background-position) on top of that using position: absolute. The sprite is a PNG with alpha-channel.
Now I'm trying to add some tint to that image (greenish or blueish or other).
I've studied the similar questions and apparently the only possible solutions are:
- Create a
divon top of the sprite with the desired color as itsbackground-color, desired tint strength asopacityand the original sprite image asmask-image(and setting themask-type: alpha). While it should work on paper, it doesn't in practice - this newdivis just invisible :( - Use
mix-blend-modefor the overlaying coloreddivand specify something likemultiplyoroverlay. It produces perfect results as long as the global background is black. If it's something else - it gets included in the calculations and the overlaydivmodifies it as well, producing a tinted rectangle instead of tinted sprite... - Use SVG filter as described in an answer here: https://stackoverflow.com/a/30949302/306470 . I didn't try this one yet, but it feels unnecessary complicated for this task. I'm concerned about the performance here too, will it slow down things a lot if there will be multiple tinted sprites on the screen at the same time? If anyone had experience with it - please comment here :)
- Prepare a tinted version of the sprite using an invisible
canvas. Sounds even more complicated, has a disadvantage of having to spend time to prepare the tinted version of the sprite, but should work as fast as the original sprite once it's prepared? Implementation should be pretty complicated though. Pure CSS solution would be much better...
Am I missing something? Are there any other options? Or should I go with #3 or #4?