スタイルtextAlignプロパティ
例
要素内のテキストを中央揃えにします。
document.getElementById("demo").style.textAlign = "center";
定義と使用法
textAlignプロパティは、ブロックレベルの要素内のテキストの水平方向の配置を設定または返します。
ブラウザのサポート
Property | |||||
---|---|---|---|---|---|
textAlign | Yes | Yes | Yes | Yes | Yes |
構文
textAlignプロパティを返します。
object.style.textAlign
textAlignプロパティを設定します。
object.style.textAlign = "left|right|center|justify|initial|inherit"
プロパティ値
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 |
技術的な詳細
デフォルト値: | 左 |
---|---|
戻り値: | 要素内のテキストの水平方向の配置を表す文字列 |
CSSバージョン | CSS1 |
その他の例
例
要素のテキスト配置を返します。
alert(document.getElementById("demo").style.textAlign);
関連ページ
CSSチュートリアル:CSSテキスト
CSSリファレンス:text-alignプロパティ
❮スタイルオブジェクト