white-space

設定指定物件內的行是否自動分行的值。

語法

{ white-space: sWrap }

可能的值

sWrap

指定下列其中一個值的字串:

normal

預設值。文字行自動分行。如果內容超過物件寬度,則換行至下一行。

nowrap

不使用分行符號。內容不會換行至下一行。

pre

分行符號和其他空白字元會保留。當 !DOCTYPE 宣告指定標準相容模式時,即可支援這個可能的值。當 !DOCTYPE 宣告未指定標準相容模式時,可以擷取此值,但它不會影響呈現,其功能類似 normal 值。

pre-line

保留分行符號的序列。

pre-wrap

摺疊分行符號的序列。

此屬性的預設值為 normal 。這是繼承屬性。

備註

根據預設,HTML 文件中的空白字元 (例如分行符號、空格和定位點) 會摺疊。當 white-space 屬性設為 normalnowrap 時,您可以使用不分行空格項目 (   ) 來新增額外的空格至物件中。您可以使用 BR 元素新增額外的分行符號。

範例

下列範例顯示當使用者將指標放在段落上時,自動分行符號如何隱藏。這是因為切換 P 元素之 onmouseoveronmouseout 事件中的 white-space 屬性值所導致的結果。當 white-space 屬性在 onmouseover 事件中設為 nowrap 時,分行符號會隱藏,並且需要水平捲動才能檢視比元素更寬的內容。當此屬性在 onmouseout 事件中設為 normal 時,會根據下列元素寬度而自動分行:

<html>
  <head><style>
      .clsOneliner  {white-space: nowrap}
      .clsAutoBreak {white-space: normal}
  </style>
    </head>
<body>
<p ONMOUSEOVER="this.className='clsOneliner';" 
        ONMOUSEOUT="this.className='clsAutoBreak';">
Long lines of text remain unbroken when the value of the whitespace 
property is set to nowrap. Place your mouse over the text to 
suppress automatic line breaks.</p>
  </body>
</html>

標準資訊

您可以在 Cascading Style Sheets (CSS), Level 1 (CSS1) (階層式樣式表 (CSS) 層級 1 (CSS1)) Ee371236.xtlink_newWindow(zh-tw,Expression.40).png 找到此屬性的定義。

適用範圍

:after , :before , abbr , acronym , address , big , blockquote , body , center , cite , code , dd , dir , div, dl , dt , em , fieldset , font , form , hn , hr , i , ins , kbd , label , legend , li , listing , menu , ol , p , plaintext , pre , q , s , small , span , strike , strong , style , sub , sup , th , tt , u , ul , xmp