Thuộc tính màu sắc phong cách
Ví dụ
Đặt màu văn bản cho các thành phần khác nhau:
document.getElementById("myH2").style.color = "#ff0000";
document.getElementById("myP").style.color = "magenta";
document.getElementById("myP2").style.color = "blue";
document.getElementById("myDiv").style.color = "lightblue";
Hãy tự mình thử »Sự miêu tả
Thuộc tính color đặt hoặc trả về màu của văn bản.
Hỗ trợ trình duyệt
Property | |||||
---|---|---|---|---|---|
color | Yes | Yes | Yes | Yes | Yes |
Cú pháp
Trả về thuộc tính màu:
object .style.color
Đặt thuộc tính màu:
object .style.color = "color |initial|inherit"
Giá trị tài sản
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 |
Chi tiết kỹ thuật
Giá trị mặc định: | không được chỉ định |
---|---|
Giá trị trả về: | Một Chuỗi, biểu thị màu văn bản của một phần tử |
Phiên bản CSS | CSS1 |
Thêm ví dụ
Ví dụ
Trả về màu văn bản của phần tử <p>:
alert(document.getElementById("myP").style.color);
Hãy tự mình thử »Trang liên quan
Hướng dẫn CSS: Văn bản CSS
Tham chiếu CSS: thuộc tính màu