如何更改元素的内联样式文本颜色而无需添加类或标识? [英] How can I change the inline style text color of an element without the ability to add a class or id?

查看:381
本文介绍了如何更改元素的内联样式文本颜色而无需添加类或标识?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在是否有可能在CSS给一个颜色名称一个替代十六进制值?,显然没有人明白我问的可能是由于我的质疑方式不好,我想我应该转发一些更好的问题措辞:

有一个网页,其代码如下,代码如下:

 < span style =color:red;> + 3000< / span> 
< span style =color:green;> -2000< / span>
< span style =color:red;> + 1500< / span>
< span style =color:red;> + 4200< / span>
< span style =color:green;> -100< / span>
< span style =color:black;> +/- 0< / span>

上面的代码写在原始网站上,我无法更改或添加class / id这些html标签。但是现在我想创建一个单独的CSS样式表,使任何加载样式表的人都能看到绿色的加号项(在原始代码中标记为红色),以及那些减号项(在原始代码中标记为绿色)在红颜色。可以吗?怎么做?

解决方案

您可以按如下方式使用属性/值选择器:

  [style * =color:red] {
color:green!important;
}

[style * =color:green] {
color:red!important;
}

您需要使用!important 关键字以避免浏览器使用内联值。


As I asked in Is it possible in css to give a color name an alternative HEX value? and apparently no one understand what i was asking probably due to my bad way of questioning, I think I should repost the question with some better wording:

There is a website which have codes like the following written in its page as exampled follow:

    <span style="color:red;">+3000</span>
    <span style="color:green;">-2000</span>
    <span style="color:red;">+1500</span>
    <span style="color:red;">+4200</span>
    <span style="color:green;">-100</span>
    <span style="color:black;">+/-0</span>

The above code are written on the original site and i cannot change it or add class/id on to those html tags. But now i want to create a separate CSS stylesheet that make anyone who load the stylesheet would see those plus items (that mark as red in the original code) in green color, and those minus items (that mark as green in the original code) in red color. Can it/How can it be done?

解决方案

You can use the attribute/value selector as follows;

[style*="color:red"] {
    color: green !important;
}

[style*="color:green"] {
    color: red !important;
}

You need to use the !important keyword to avoid the browser using the inline value.

这篇关于如何更改元素的内联样式文本颜色而无需添加类或标识?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆