Thuộc tính màu phong cách
Thí dụ
Đặt màu văn bản cho các phần tử 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";
Định nghĩa và Cách sử dụng
Thuộc tính màu đặ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ả lại 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ả lại: | Một chuỗi, đại diện cho màu văn bản của một phần tử |
Phiên bản CSS | CSS1 |
Các ví dụ khác
Thí dụ
Trả lại màu văn bản của phần tử <p>:
alert(document.getElementById("myP").style.color);
Các trang liên quan
Hướng dẫn CSS: Văn bản CSS
Tham chiếu CSS: thuộc tính màu
❮ Đối tượng phong cách