Propriedade textAlign do estilo
Exemplo
Centralize o texto em um elemento:
document.getElementById("demo").style.textAlign = "center";
Definição e uso
A propriedade textAlign define ou retorna o alinhamento horizontal do texto em um elemento de nível de bloco.
Suporte ao navegador
Property | |||||
---|---|---|---|---|---|
textAlign | Yes | Yes | Yes | Yes | Yes |
Sintaxe
Retorne a propriedade textAlign:
object.style.textAlign
Defina a propriedade textAlign:
object.style.textAlign = "left|right|center|justify|initial|inherit"
Valores de propriedade
Value | Description |
---|---|
left | Aligns the text to the left. This is default |
right | Aligns the text to the right |
center | Centers the text |
justify | The text is justified |
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: | deixou |
---|---|
Valor de retorno: | Uma String, representando o alinhamento horizontal do texto dentro do elemento |
Versão CSS | CSS1 |
Mais exemplos
Exemplo
Retornar o alinhamento de texto de um elemento:
alert(document.getElementById("demo").style.textAlign);
Páginas relacionadas
Tutorial CSS: Texto CSS
Referência CSS: propriedade text-align
❮ Objeto de estilo