Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to invert text color according to what's behind it? (not only background)

All the solutions I have found only work inverting the color of the text element, according to the color of the background. I want the color of the text to be inverted according to whatever is placed behind it (images, videos, 3D models etc.).

I have some sticky elements in my page, I want their color to change dynamically as the user is scrolling to the inverted color of whatever is displayed behind the text at that moment.

Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I thought mix-blend-mode: difference; would do just that. ✌️

#bg {
  background-image:url(https://thumbs.dreamstime.com/b/beautiful-multicolored-bokeh-lights-holiday-glitter-background-christmas-new-year-birthday-celebration-high-resolution-image-133585052.jpg);
}
#test {
  font-size:20vw;
  color:#FFF;
  mix-blend-mode: difference;
}
<div id="bg">
<div id="test">testing</div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading