设置不同元素的文本颜色:
document.getElementById("myH2").style.color = "#ff0000";
document.getElementById("myP").style.color = "magenta";
document.getElementById("myP2").style.color = "blue";
document.getElementById("myDiv").style.color = "lightblue";
亲自试一试 »
color 属性设置或返回文本的颜色。
Property | |||||
---|---|---|---|---|---|
color | Yes | Yes | Yes | Yes | Yes |
返回颜色属性:
object.style.color
设置颜色属性:
object.style.color
= "color|initial|inherit"
Value | Description |
---|---|
color | Specifies the color of the text. Look at CSS Color Values for a complete list of possible color values |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
默认值: | 未指定 |
---|---|
返回值: | 一个字符串,表示元素的文本颜色 |
CSS版本 | CSS1 |
CSS教程:CSS 文本
CSS 参考:颜色属性
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!