简体   繁体   English

如果正文/背景颜色为白色,请更改链接颜色

[英]Change link color if body/background color is white

Links on our website in an element with the class "elementor-text-editor" are styled with this color rule:我们网站上“elementor-text-editor”类元素中的链接使用以下颜色规则进行样式设置:

.elementor-text-editor a {
    color: #e9741f;
}

How can we automatically change the link color to #ffd329 if the link appears on a white background?如果链接出现在白色背景上,我们如何自动将链接颜色更改为#ffd329? (if the link appears in an element, such as a div, with a color other than #fff, we would not want the link color to change) (如果链接出现在一个元素中,例如一个 div,颜色不是 #fff,我们不希望链接颜色改变)

In CSS, use the Child Combinator ( > ) Selector to color a URL differently based on what container it is in. So, for example, you would have a #white-background and #blue-background div 's, each differently colored.在 CSS 中,使用子组合器 ( > ) 选择器根据 URL 所在的容器对 URL 进行不同的着色。因此,例如,您将有一个#white-background#blue-background div ,它们的颜色各不相同。 Then you'd be able to affect just one background with...然后你就可以只影响一个背景......

#blue-background > .elementor-text-editor { ... }

What happens within the ... will only affect links with a blue background ....发生的事情只会影响蓝色背景的链接。 Demo...演示...

 .elementor-text-editor { color: #e9741f } #blue-background > .elementor-text-editor { color: #FFFFFF; } #white-background { background-color:white; } #blue-background { background-color:blue; }
 <div id="white-background"> <a class="elementor-text-editor" href="wikipedia.org">link1</a> </div> <div id="blue-background"> <a class="elementor-text-editor" href="wikipedia.org">link2</a> </div>

Disclaimer: This will only work for static -positioned elements.免责声明:这仅适用于static元素。 If you have absolute elements, or anything fancy like that, you'll need to think of another approach.如果您有absolute元素或类似的东西,则需要考虑另一种方法。 I don't see enough detail to give further advice, though.不过,我看不到足够的细节来提供进一步的建议。

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

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