Propriedade de fonte de estilo
Exemplo
Defina a fonte para um elemento:
document.getElementById("demo").style.font = "italic bold 20px arial,serif";
Definição e uso
A propriedade font define ou retorna até seis propriedades de fonte separadas, em uma forma abreviada.
Com esta propriedade, você pode definir/retornar o seguinte (nesta ordem):
- estilo de fonte
- variante de fonte
- espessura da fonte
- tamanho da fonte
- altura da linha
- família de fontes
O tamanho da fonte e a família da fonte são obrigatórios. Se um dos outros valores estiver faltando, os valores padrão serão inseridos, se houver.
As propriedades acima também podem ser definidas com propriedades de estilo separadas. O uso de propriedades separadas é altamente recomendado para autores não avançados para melhor controlabilidade.
Suporte ao navegador
Property | |||||
---|---|---|---|---|---|
font | Yes | Yes | Yes | Yes | Yes |
Sintaxe
Retorne a propriedade da fonte:
object.style.font
Defina a propriedade da fonte:
object.style.font = "font-style font-variant font-weight font-size/line-height|caption|icon|menu|
message-box|small-caption|status-bar|initial|inherit;"
Valores de propriedade
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 |
Detalhes técnicos
Valor padrão: | não especificado |
---|---|
Valor de retorno: | Uma String, representando diferentes propriedades de fonte do elemento |
Versão CSS | CSS1 |
Mais exemplos
Exemplo
Retorna a fonte de um elemento:
alert(document.getElementById("demo").style.font);
Páginas relacionadas
Tutorial CSS: Fonte CSS
Referência CSS: propriedade da fonte
❮ Objeto de estilo