简体   繁体   English

如果背景图像不是白色,请更改文字颜色?

[英]Change text color if background image is not white?

I have read a lot articles about this but haven't found anything to solve my problem. 我已经阅读了很多关于此的文章,但没有找到任何解决我问题的方法。

Is it possible somehow to change text color based on background image with Jquery or/and CSS? 是否有可能以某种方式使用Jquery或/和CSS更改基于背景图像的文本颜色?

I have to make a responsive website with this requested, but got stuck. 我必须根据要求建立一个响应式网站,但卡住了。

在此输入图像描述

An idea is to color the text with an inverted background. 一个想法是用反转的背景为文本着色。

Here is an idea considering radial-gradient : 这是一个考虑radial-gradient的想法:

 .box { padding: 50px; background: radial-gradient(circle at 70% 0px, #fff 45%, purple 45.5%) fixed; } p { font-size: 25px; font-weight: bold; /*Should be the same background but inverted color*/ background: radial-gradient(circle at 70% 0px, purple 45%, #fff 45.5%) fixed; background-clip: text; color: transparent; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } 
 <div class="box"> <p>Some text here Some text here Some text here Some text here </p> </div> 

In your case, the background seems to be an image so you simply need to find a gradient that is similar where you can invert the colors. 在您的情况下,背景似乎是一个图像,因此您只需要找到一个类似于可以反转颜色的渐变。

Another Idea is to use a basic image and add an overlay to create the result: 另一个想法是使用基本图像并添加叠加层来创建结果:

 .box { padding: 50px; background: radial-gradient(circle at 70% 0px, #fff 35%, rgba(27, 128, 0, 0.6) 35.5%), url(https://picsum.photos/500/800?image=1069) center/cover; background-attachment:fixed; } p { font-size: 25px; font-weight: bold; /*Should be the same background but inverted color*/ background: radial-gradient(circle at 70% 0px, rgba(27, 128, 0, 1) 35%, #fff 35.5%) fixed; background-clip: text; color: transparent; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } 
 <div class="box"> <p>Some text here Some text here Some text here Some text here </p> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM