Proprietà del carattere di stile
Esempio
Imposta il carattere per un elemento:
document.getElementById("demo").style.font = "italic bold 20px arial,serif";
Definizione e utilizzo
La proprietà del carattere imposta o restituisce fino a sei proprietà del carattere separate, in forma abbreviata.
Con questa proprietà, puoi impostare/restituire quanto segue (in questo ordine):
- stile carattere
- font-variante
- peso del carattere
- dimensione del font
- altezza della linea
- famiglia di font
La dimensione del carattere e la famiglia di caratteri sono obbligatori. Se uno degli altri valori manca, verranno inseriti i valori di default, se presenti.
Le proprietà di cui sopra possono anche essere impostate con proprietà di stile separate. L'uso di proprietà separate è altamente raccomandato per gli autori non esperti per una migliore controllabilità.
Supporto browser
Property | |||||
---|---|---|---|---|---|
font | Yes | Yes | Yes | Yes | Yes |
Sintassi
Restituisce la proprietà del carattere:
object.style.font
Imposta la proprietà del carattere:
object.style.font = "font-style font-variant font-weight font-size/line-height|caption|icon|menu|
message-box|small-caption|status-bar|initial|inherit;"
Valori di proprietà
Value | Description |
---|---|
style | Sets the font-style |
variant | Sets the text in a small-caps font |
weight | Sets the boldness of the font |
size | Sets the size of the font |
lineHeight | Sets the distance between lines |
family | Sets the font face |
caption | The font used for captioned controls (like buttons, drop-downs, etc.) |
icon | The font used to label icons |
menu | The font used in menus |
message-box | The font used in dialog boxes |
small-caption | The font used in small controls |
status-bar | The font used in window status bars |
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: | non specificato |
---|---|
Valore di ritorno: | Una stringa, che rappresenta le diverse proprietà del carattere dell'elemento |
Versione CSS | CSS1 |
Altri esempi
Esempio
Restituisce il carattere di un elemento:
alert(document.getElementById("demo").style.font);
Pagine correlate
Tutorial CSS: Font CSS
Riferimento CSS: proprietà del carattere
❮ Oggetto stile