Properti warna gaya
Contoh
Atur warna teks untuk elemen yang berbeda:
document.getElementById("myH2").style.color = "#ff0000";
document.getElementById("myP").style.color = "magenta";
document.getElementById("myP2").style.color = "blue";
document.getElementById("myDiv").style.color = "lightblue";
Definisi dan Penggunaan
Properti warna mengatur atau mengembalikan warna teks.
Dukungan Peramban
Property | |||||
---|---|---|---|---|---|
color | Yes | Yes | Yes | Yes | Yes |
Sintaksis
Kembalikan properti warna:
object.style.color
Setel properti warna:
object.style.color = "color|initial|inherit"
Nilai properti
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 |
Detail Teknis
Nilai Bawaan: | tidak ditentukan |
---|---|
Nilai Kembali: | Sebuah String, mewakili warna teks dari suatu elemen |
Versi CSS | CSS1 |
Lebih Banyak Contoh
Contoh
Kembalikan warna teks dari elemen <p>:
alert(document.getElementById("myP").style.color);
Halaman Terkait
Tutorial CSS: Teks CSS
Referensi CSS: properti warna
Objek Gaya