text-align
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since julho de 2015.
* Some parts of this feature may have varying levels of support.
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 is ltr, right if direction 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
startExperimental-
Igual
leftse a direção é esquerda-para-direita erightse a direção é direita-para-esquerda. endExperimental-
Igual
rightse a direção é esquerda-para-direita eleftse 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-parentExperimental-
Similar to
inherit, but the valuesstartandendare calculated according the parent'sdirectionand are replaced by the adequateleftorrightvalue.
Sintaxe Formal
text-align =
start |
end |
left |
right |
center |
<string> |
justify |
match-parent |
justify-all
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
| Specification |
|---|
| CSS Logical Properties and Values Level 1> # text-align> |
| CSS Text Module Level 3> # text-align-property> |
Browser compatibilidade
Loading…