スタイルシート属性 line-break は、行末の禁則処理を指定します。
禁則処理とは、行の先頭に来ることが望ましくない文字が、行の先頭に来ないように改行位置を調整することです。通常、日本語の文章では句読点や拗音は行の先頭に来ることはありません。
line-break: mode
値 | 意味 |
---|---|
auto | User 既定の改行規則を使用してテキストを改行する。 |
loose | 最も制約の少ない改行規則でテキストを改行する。一般に、新聞などの短い行に使用される。 |
normal | 最も一般的な改行規則でテキストを改行する。 |
strict | 最も厳しい改行規則でテキストを改行する。 |
anywhere | 改行に対するあらゆる禁止を無視する。 |
次にスタイルシート属性 line-break を使用したHTMLの例を示します。
<p style="line-break: auto;">
私はその様子を見て、
「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
</p>
私はその様子を見て、「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
<p style="line-break: loose;">
私はその様子を見て、
「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
</p>
私はその様子を見て、「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
<p style="line-break: normal;">
私はその様子を見て、
「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
</p>
私はその様子を見て、「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
<p style="line-break: strict;">
私はその様子を見て、
「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
</p>
私はその様子を見て、「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
<p style="line-break: anywhere;">
私はその様子を見て、
「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
</p>
私はその様子を見て、「各々皆、並々ならぬ努力をしているのだなぁ」と思った。
スタイルシート属性 word-break は、行末の改行処理を指定します。
word-break: mode
値 | 意味 |
---|---|
normal | 和文は単語の途中でも改行、英文は単語の切れ目で改行(規定値) |
break-all | 単語の途中でも改行 |
keep-all | 単語の切れ目で改行 |
Webブラウザ | 対応状況 |
---|---|
Internet Explorer 6.0 | ○ |
FireFox 3.0 | ×1 |
Google Chrome 0.3 | ○ |
Opera 9.62 | ×1 |
Safari 3.2 | ○ |
1 常に単語の切れ目で改行する。
次にスタイルシート属性 word-break を使用したHTMLの例を示します。
<p style="word-break: break-all; width: 20em">This is HTML 4.01 Strict DTD, which excludes the presentation attributes and elements that W3C expects to phase out as support for style sheets matures. Authors should use the Strict DTD when possible, but may use the Transitional DTD when support for presentation attribute and elements is required.</p>
This is HTML 4.01 Strict DTD, which excludes the presentation attributes and elements that W3C expects to phase out as support for style sheets matures. Authors should use the Strict DTD when possible, but may use the Transitional DTD when support for presentation attribute and elements is required.
<p style="word-break: keep-all; width: 20em">This is HTML 4.01 Strict DTD, which excludes the presentation attributes and elements that W3C expects to phase out as support for style sheets matures. Authors should use the Strict DTD when possible, but may use the Transitional DTD when support for presentation attribute and elements is required.</p>
This is HTML 4.01 Strict DTD, which excludes the presentation attributes and elements that W3C expects to phase out as support for style sheets matures. Authors should use the Strict DTD when possible, but may use the Transitional DTD when support for presentation attribute and elements is required.
white-spaceは、空白文字及び自動改行の扱いを指定するスタイルシート属性である。
white-space: space
値 | 意味 |
---|---|
normal | 自動改行あり、空白は詰める。(初期値) |
pre | 自動改行なし、空白はそのまま。 |
nowrap | 自動改行なし、空白は詰める。 |
pre-wrap | 自動改行あり、空白はそのまま。 |
pre-line | 連続する空白、タブ及び改行をひとつの空白として表示する。自動改行する。 |
inherit | 上位要素のスタイルを継承する。 |
すべての要素
次にスタイルシート属性 white-space
の使用例と表示サンプルを示す。表示結果はブラウザによって異なることがある。
<p style="white-space:pre">white space</p>
white space
<p style="white-space:nowrap">white space</p>
white space
<p style="white-space: pre-wrap">white space white space white space white space white space white space</p>
white space white space white space white space white space white space
World Wide Web Consortium (2021) CSS Text Module Level 3
CSSには次のプロパティがある。