On my Anki flashcards, I've implemented a stylish transparent gradient for text using CSS:
background: -webkit-linear-gradient(-45deg, #cccccc, #ffffff);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
Currently, this is specific to my Anki cards, so cross-browser compatibility isn't a concern at the moment.
I'd like to dynamically change the colors of the gradient using Javascript. However, simply setting the gradient with
document.getElementById("ID_of_Text").style.background=
"-webkit-linear-gradient(-45deg, #000000, #ffffff)"
only changes the color of the gradient itself, removing the text and transparency properties.
https://i.sstatic.net/rW3QI.png
Should I reapply -webkit-background-clip:text
and
-webkit-text-fill-color: transparent
? I have attempted to do so, but it doesn't seem to be working. Perhaps I'm missing something.