Stile backgroundColor Proprietà
Esempio
Imposta un colore di sfondo per un documento:
document.body.style.backgroundColor = "red";
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
La proprietà backgroundColor imposta o restituisce il colore di sfondo di un elemento.
Supporto browser
I numeri nella tabella specificano la prima versione del browser che supporta completamente la proprietà.
Property | |||||
---|---|---|---|---|---|
backgroundColor | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintassi
Restituisce la proprietà backgroundColor:
object.style.backgroundColor
Imposta la proprietà backgroundColor:
object.style.backgroundColor = "color|transparent|initial|inherit"
Valori di proprietà
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 |
Dettagli tecnici
Valore di default: | trasparente |
---|---|
Valore di ritorno: | Una stringa, che rappresenta il colore di sfondo |
Versione CSS | CSS1 |
Altri esempi
Esempio
Imposta un colore di sfondo di un elemento <div> specifico:
document.getElementById("myDiv").style.backgroundColor = "lightblue";
Esempio
Restituisce il colore di sfondo di un elemento <div> specifico:
alert(document.getElementById("myDiv").style.backgroundColor);
Esempio
Restituisce il colore di sfondo di un documento:
alert(document.body.style.backgroundColor);
Pagine correlate
Tutorial CSS: Sfondo CSS
Riferimento CSS: proprietà background-color
Riferimento HTML DOM: proprietà in background