css white-space屬性的使用及定義詳解

來源:互聯網
上載者:User
CSS的white-space屬性用於指定如何處理容器中的空白字元,例如:空格( )、換行(\n)、縮排(\t)等。

white-space出自CSS1,適用於塊狀元素,具有繼承性,支援IE 5.5+、Chrome、FireFox、Safari、Opera等所有主流瀏覽器,其預設值為normal。

文法:

white-space : normal | pre | nowrap

參數:

normal :  預設處理方式
pre :  用等寬字型顯示預先格式化的文本。不合并字間的空白距離和進行左右對齊。參閱pre對象
nowrap :  強制在同一行內顯示所有文本,直到文本結束或者遭遇br對象。參閱td,div等對象的nowrap屬性(特性)

說明:

設定或檢索對象內空格的處理方式。
對應的指令碼特性為whiteSpace。請參閱我編寫的其他書目。

樣本:

p { white-space: nowrap; }


說明

white-space支援normal、pre、nowrap、pre-wrap、pre-line、inherit等值。下面我們來詳細介紹這些值之間的區別。

JavaScript操作

white-space在JavaScript中對應的屬性名稱為whiteSpace,例如:

document.getElementById("p1").style.whiteSpace = "nowrap";

style對象上的whiteSpace屬性是可讀寫的,但是currentStyle對象上的whiteSpace屬性是唯讀。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.