CSS強制性換行word-break與word-wrap的使用,css不換行wordwrap

來源:互聯網
上載者:User

CSS強制性換行word-break與word-wrap的使用,css不換行wordwrap

一般情況下,元素擁有預設的white-space:normal(自動換行,不換行是white-space:nowrap),當錄入的文字超過定義的寬度後會自動換行,但當錄入的資料是一堆沒有空格的字元或字母或數字(常規資料應該不會有吧,但有些測試人員是會這樣子做的),超過容器寬度時就會把容器撐大,不換行。

所以解決方案(以IE,chrome,FF為測試瀏覽器)有兩種寫法:

{

word-break:break-all; 

word-wrap:break-word;

}

兩種方法的區別說明:

1,word-break:break-all 例如div寬400px,它的內容就會到400px自動換行,如果該行末端有個英文單詞很長(congratulation等),它會把單詞截斷,變成該行末端為conra(congratulation的前端部分),下一行為tulation(conguatulation)的後端部分了。

2,word-wrap:break-word 例子與上面一樣,但區別就是它會把congratulation整個單詞看成一個整體,如果該行末端寬度不夠顯示整個單詞,它會自動把整個單詞放到下一行,而不會把單詞截斷掉的。

 

html代碼:

<div style="width:400px;background:#000;color:#fff;height:100px;margin:0 auto;word-break:break-all; ">    congratulation congratulation congratulation congratulation congratulation congratulation</div></br/><div style="width:400px;height:100px;background:#000;color:#fff;margin:0 auto;word-wrap:break-word;">    congratulation congratulation congratulation congratulation congratulation congratulation</div>

 

結果:

這樣就一目瞭然了。

 

作者:風雨後見彩虹

出處:http://www.cnblogs.com/moqiutao/

如果您覺得本文對您的學習有所協助,請多支援與鼓勵。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.