CSS - white-space

トップ > CSSリファレンス > white-space

概要

属性名 white-space
normal | pre | nowrap | pre-wrap | pre-line
初期値各要素によって異なる
適用可能要素すべての要素
継承継承する
メディアVisual / Text
サポートC1 / e6 / N4 / Fx1 / Ch1 / Op4 / Sa1

説明

要素の中のテキストを、自動改行するか、複数の空白をひとつの空白に置換するか、改行を空白に置換するかを指定します。

説明
normal自動改行します。複数の空白・タブ・改行をひとつの空白に置換します。(C1/e6/N4/Fx1/Ch1/Op4/Sa1)
pre自動改行しません。空白・タブ・改行はそのまま表示します。(C1/e6/N4/Fx1/Ch1/Op4/Sa1)
nowrap自動改行しません。複数の空白・タブ・改行をひとつの空白に置換します。(C1/e6/N4/Fx1/Ch1/Op4/Sa1)
pre-wrap自動改行します。空白・タブ・改行はそのまま表示します。(C2/e/Fx/Ch/Op/Sa)
pre-line自動改行します。複数の空白・タブをひとつの空白に置換します。ただし改行はそのまま表示します。(C2/e/Fx/Ch/Op/Sa)

使用例

CSS
.sample-normal {
    white-space: normal;
    margin: 1em;
    width: 300px;
    border: 1px solid #666666;
}
.sample-pre {
    white-space: pre;
    margin: 1em;
    width: 300px;
    border: 1px solid #666666;
}
.sample-nowrap {
    white-space: nowrap;
    margin: 1em;
    width: 300px;
    border: 1px solid #666666;
}
.sample-pre-wrap {
    white-space: pre-wrap;
    margin: 1em;
    width: 300px;
    border: 1px solid #666666;
}
.sample-pre-line {
    white-space: pre-line;
    margin: 1em;
    width: 300px;
    border: 1px solid #666666;
}
HTML
<h5>normal</h5>
<div class="sample-normal">
This   is   short   sentence.
This   is   very   very   very   very   very   long   sentence.
</div>

<h5>pre</h5>
<div class="sample-pre">
This   is   short   sentence.
This   is   very   very   very   very   very   long   sentence.
</div>

<h5>nowrap</h5>
<div class="sample-nowrap">
This   is   short   sentence.
This   is   very   very   very   very   very   long   sentence.
</div>

<h5>pre-wrap</h5>
<div class="sample-pre-wrap">
This   is   short   sentence.
This   is   very   very   very   very   very   long   sentence.
</div>

<h5>pre-line</h5>
<div class="sample-pre-line">
This   is   short   sentence.
This   is   very   very   very   very   very   long   sentence.
</div>
表示
normal
This is short sentence. This is very very very very very long sentence.
pre
This is short sentence. This is very very very very very long sentence.
nowrap
This is short sentence. This is very very very very very long sentence.
pre-wrap
This is short sentence. This is very very very very very long sentence.
pre-line
This is short sentence. This is very very very very very long sentence.

Copyright (C) 1997-2012 杜甫々
初版:1997年7月27日、最終更新:2012年5月4日
http://www.tohoho-web.com/css/prop/white-space.htm