text-align
Sumário
A propriedade CSS text-align
descreve como conteúdo inline, como texto, é alinhado no elemento pai em bloco. text-align
não controla o alinhamento de elementos em bloco, apenas o seu conteúdo inline.
Initial value | start , or a nameless value that acts as left if direction (en-US) is ltr , right if direction (en-US) is rtl if start is not supported by the browser. |
---|---|
Aplica-se a | block containers |
Inherited | yes |
Computed value | as specified, except for the match-parent value which is calculated against its parent's direction value and results in a computed value of either left or right |
Animation type | discrete |
Sintaxe
/* Keyword values */
text-align: left;
text-align: right;
text-align: center;
text-align: justify;
text-align: justify-all;
text-align: start;
text-align: end;
text-align: match-parent;
/* Block alignment values (Non-standard syntax) */
text-align: -moz-center;
text-align: -webkit-center;
/* Global values */
text-align: inherit;
text-align: initial;
text-align: unset;
Valores
start
Experimental-
Igual
left
se a direção é esquerda-para-direita eright
se a direção é direita-para-esquerda. end
Experimental-
Igual
right
se a direção é esquerda-para-direita eleft
se a direção é direita-para-esquerda. left
-
O conteúdo é alinhado na borda esquerda do box.
right
-
O conteúdo é alinhado na borda direita do box.
center
-
Os conteúdos inline são centralizados entre a linha da caixa.
justify
-
Os conteúdos inline são justificados. Text should be spaced to line up its left and right edges to the left and right edges of the line box, except for the last line.
justify-all
-
Semelhante a
justify
, porém força a última linha a ser justificada. match-parent
Experimental-
Similar to
inherit
, but the valuesstart
andend
are calculated according the parent'sdirection
(en-US) and are replaced by the adequateleft
orright
value.
Sintaxe Formal
Exemplos
Alinhamento Esquerdo
HTML
<p class="example">
Integer elementum massa at nulla placerat varius.
Suspendisse in libero risus, in interdum massa.
Vestibulum ac leo vitae metus faucibus gravida ac in neque.
Nullam est eros, suscipit sed dictum quis, accumsan a ligula.
</p>
CSS
.example {
text-align: left;
border: solid;
}
Resultado
Texto centralizado
HTML
<p class="example">
Integer elementum massa at nulla placerat varius.
Suspendisse in libero risus, in interdum massa.
Vestibulum ac leo vitae metus faucibus gravida ac in neque.
Nullam est eros, suscipit sed dictum quis, accumsan a ligula.
</p>
CSS
.example {
text-align: center;
border: solid;
}
Resultado
Justificado
HTML
<p class="example">
Integer elementum massa at nulla placerat varius.
Suspendisse in libero risus, in interdum massa.
Vestibulum ac leo vitae metus faucibus gravida ac in neque.
Nullam est eros, suscipit sed dictum quis, accumsan a ligula.
</p>
CSS
.example {
text-align: justify;
border: solid;
}
Resultado
Notas
O modo compátivel-padrão de centralizar um bloco em si sem centralizar seu conteúdo inline é setando a margin
left e right para auto
, e.g.:
.something {
margin: auto;
}
.something {
margin: 0 auto;
}
.something {
margin-left: auto;
margin-right: auto;
}
Especificações
Especificação | Status | Comentário |
---|---|---|
CSS Logical Properties and Values Level 1 The definition of 'text-align' in that specification. |
Rascunho editorial | Sem mudanças |
CSS Text Module Level 3 The definition of 'text-align' in that specification. |
Candidata a Recomendação | Added the start , end , and match-parent values. Changed the unnamed initial value to start (which it was). |
CSS Level 2 (Revision 1) The definition of 'text-align' in that specification. |
Recomendação | Sem mudanças |
CSS Level 1 The definition of 'text-align' in that specification. |
Recomendação | Definição iniciaç |
Browser compatibilidade
BCD tables only load in the browser