How can I change the inline style text color of an element without the ability to add a class or id?

喜你入骨 提交于 2019-12-11 03:44:17

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25474104/how-can-i-change-the-inline-style-text-color-of-an-element-without-the-ability-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!