Latar belakang gayaProperti Warna
Contoh
Mengatur warna latar belakang untuk dokumen:
document.body.style.backgroundColor = "red";
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Properti backgroundColor menyetel atau mengembalikan warna latar belakang suatu elemen.
Dukungan Peramban
Angka-angka dalam tabel menentukan versi browser pertama yang sepenuhnya mendukung properti.
Property | |||||
---|---|---|---|---|---|
backgroundColor | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintaksis
Kembalikan properti backgroundColor:
object.style.backgroundColor
Setel properti backgroundColor:
object.style.backgroundColor = "color|transparent|initial|inherit"
Nilai properti
Value | Description |
---|---|
color | Specifies the background color. Look at CSS Color Values for a complete list of possible color values |
transparent | Default. The background color is transparent (underlying content will shine through) |
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: | transparan |
---|---|
Nilai Kembali: | Sebuah String, mewakili warna latar belakang |
Versi CSS | CSS1 |
Lebih Banyak Contoh
Contoh
Setel warna latar belakang elemen <div> tertentu:
document.getElementById("myDiv").style.backgroundColor = "lightblue";
Contoh
Kembalikan warna latar belakang elemen <div> tertentu:
alert(document.getElementById("myDiv").style.backgroundColor);
Contoh
Mengembalikan warna latar belakang dokumen:
alert(document.body.style.backgroundColor);
Halaman Terkait
Tutorial CSS: Latar Belakang CSS
Referensi CSS: properti warna latar belakang
Referensi DOM HTML: properti latar belakang