如何使用Java脚本更改网站所有文本的字体颜色? [英] How can I change the font color of all texts of your website using Javascript?
问题描述
我了解到,有多种方法可以更改单个文本的颜色.但是,我想一次了解如何更改网站所有文本的颜色.
I learned, that there are ways to change the color of single texts. However I'd like to find out how to change the color of all texts of my website at one time.
我找到了document.body.style.backgroundColor = "black";
函数,并希望字体会有类似的东西.
I found the document.body.style.backgroundColor = "black";
function and hoped that there would be something similar for fonts.
对不起.我想我在误导一些人.我知道CSS是什么……我想找到一种在使用网站时更改颜色的方法.因此,我想找到一种通过JavaScript更改CSS属性的方法.
I am sorry. I guess I was misleading some people. I know what CSS is ofcourse... I wanted to find a way to change the colors while using the website. So I'd like to find a way to change the CSS properties via JavaScript.
推荐答案
使用 CSS
* {
color: [color-value];
}
这将使用通用(*
)选择器更改所有元素的字体颜色.如有必要,您可能需要使用 !important
声明(不推荐使用,但有用:请参见链接)以覆盖其他样式.
This will change the font color of all elements using the universal (*
) selector. If necessary, you may need to use the !important
declaration (not recommended, but useful: see link) to override other styles.
JavaScript
document.body.style.color = [color-value];
这篇关于如何使用Java脚本更改网站所有文本的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!