Propriété d'alignement du texte de style
Exemple
Centrer le texte dans un élément :
document.getElementById("demo").style.textAlign = "center";
Définition et utilisation
La propriété textAlign définit ou renvoie l'alignement horizontal du texte dans un élément de niveau bloc.
Prise en charge du navigateur
Property | |||||
---|---|---|---|---|---|
textAlign | Yes | Yes | Yes | Yes | Yes |
Syntaxe
Renvoyez la propriété textAlign :
object.style.textAlign
Définissez la propriété textAlign :
object.style.textAlign = "left|right|center|justify|initial|inherit"
Valeurs de propriété
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 |
Détails techniques
Valeur par défaut: | à gauche |
---|---|
Valeur de retour : | Une chaîne, représentant l'alignement horizontal du texte dans l'élément |
Version CSS | CSS1 |
Plus d'exemples
Exemple
Renvoie l'alignement du texte d'un élément :
alert(document.getElementById("demo").style.textAlign);
Pages connexes
Tutoriel CSS : Texte CSS
Référence CSS : propriété text-align
❮ Objet de style