テキストの揃え方(水平方向・垂直方向)に関するスタイルシート属性

text-align

スタイルシート属性text-alignは、テキストの揃え方を指定します。

書式

text-align: align

属性値

alignにはテキストの並びの揃え方を指定します。

align
意味
left左端揃え(規定値)
center中央揃え
right右端揃え
justify両端揃え
inherit継承

スタイルシート属性text-alignの属性値としてjustifyを指定した場合、スタイルシート属性text-justifyでさらにテキストの揃え方を細かく指定することができます。

使用例と表示サンプル

次にスタイルシート属性 text-alignを使用したHTMLの例を示します。

<p style="text-align:left">text-align is left</p>
<p style="text-align:center">text-align is center</p>
<p style="text-align:right">text-align is right</p>
<p style="text-align:justify">text-align is justify</p>

This paragraph's stylesheet attribute is "text-align: left".

This paragraph's stylesheet attribute is "text-align: center".

This paragraph's stylesheet attribute is "text-align: right".

This paragraph's stylesheet attribute is "text-align: justify".

text-justify

スタイルシート属性text-justifyは、単語間や文字間のスペースの調整の仕方を指定します。 通常、スタイルシート属性 text-align: justify; と組み合わせて使用します。

書式

text-justify: type

次にtypeに指定できる値を示します。

意味
auto自動(規定値)
newspaper英文
inter-word単語間のみによる調整
distribute-all-lines最後の行も調整
inter-ideograph単語間と文字間
inter-clusterアジア言語向き
distributeタイ語向き
kashidaアラビア語向き

次にスタイルシート属性 text-justifyを使用したHTMLの例を示します。

<p style="text-align: justify; text-justify: auto">This paragraph's stylesheet attribute is "text-align: justify; text-justify: auto".</p>
<p style="text-align: justify; text-justify: newspaper">This paragraph's stylesheet attribute is "text-align: justify; text-justify: newspaper".</p>
<p style="text-align: justify; text-justify: inter-word">This paragraph's stylesheet attribute is "text-align: justify; text-justify: inter-word".</p>
<p style="text-align: justify; text-justify: distribute-all-lines">This paragraph's stylesheet attribute is "text-align: justify; text-justify: distribute-all-lines".</p>
<p style="text-align: justify; text-justify: inter-ideograph">This paragraph's stylesheet attribute is "text-align: justify; text-justify: inter-ideograph".</p>

This paragraph's stylesheet attribute is "text-align: justify; text-justify: auto".

This paragraph's stylesheet attribute is "text-align: justify; text-justify: newspaper".

This paragraph's stylesheet attribute is "text-align: justify; text-justify: inter-word".

This paragraph's stylesheet attribute is "text-align: justify; text-justify: distribute-all-lines".

This paragraph's stylesheet attribute is "text-align: justify; text-justify: inter-ideograph".

text-indent

スタイルシート属性text-indentは、テキストのインデント(字下げ)を指定します。

書式

text-indent: indent

属性値

indentにはテキストのインデント(字下げ)幅を指定します。1emのように数値と単位で指定するか、次の値から指定します。

indent
意味
inherit継承

使用例

スタイルシート属性 text-indent を使用した HTML の例を次に示します。表示結果はブラウザによって異なることがあります。

<p style="text-indent: 0em">0em</p>
<p style="text-indent: 1em">1em</p>
<p style="text-indent: 2em">2em</p>

0em

1em

2em

<p style="text-indent: 10px">10px</p>
<p style="text-indent: 20px">20px</p>
<p style="text-indent: 30px">30px</p>

10px

20px

30px

vertical-align

スタイルシート属性vertical-alignは、テキストの縦方向の位置を指定します。

書式

vertical-align: align

属性値

align
テキストの縦方向の位置を次の値の中から指定します。baseline はアルファベット x の下端を基準とした線です。text-bottom は文字 y の下端を基準とした線です。
意味
baselineベースライン
middle中央合わせ
sub下付き文字
super上付き文字
text-topテキストの上限合わせ
text-bottomテキストの下限合わせ
top上端
bottom下端
inherit継承

使用例

次にスタイルシート属性 vertical-align を使用したHTMLの例を示します。

<span style="vertical-align: baseline">baseline</span>
<span style="vertical-align: middle">middle</span>
<span style="vertical-align: sub">sub</span>
<span style="vertical-align: super">super</span>
<span style="vertical-align: text-top">text-top</span>
<span style="vertical-align: text-bottom">text-bottom</span>
<span style="vertical-align: top">top</span>
<span style="vertical-align: bottom">bottom</span>
baseline middle sub super text-top text-bottom top bottom
SEO 仕事 掲示板 レンタルサーバー プロフ SEO