CSS如何?英文與連續數字自動換行的執行個體詳解

來源:互聯網
上載者:User
對於p,p等區塊層級元素

  正常文字的換行(亞洲文字和非亞洲文字)元素擁有預設的white-space:normal,當定義的寬度之後自動換行:

 html<p id="wrap">正常文字的換行(亞洲文字和非亞洲文字)元素擁有預設的white-space:normal,當定義</p>  css#wrap{white-space:normal; width:200px; }

   1.(IE瀏覽器)連續的英文字元和阿拉伯數字,使用word-wrap : break-word ;或者word-break:break-all;實現強制斷行

 #wrap{word-break:break-all; width:200px;}

  或者

#wrap{word-wrap:break-word; width:200px;}  <p id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</p>

  效果:可以實現換行

  2.(Firefox瀏覽器)連續的英文字元和阿拉伯數位斷行,Firefox的所有版本的沒有解決這個問題,我們只有讓超出邊界的字元隱藏或者,給容器添加捲軸

#wrap{word-break:break-all; width:200px; overflow:auto;}  <p id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</p>

  效果:容器正常,內容隱藏

對於table

  1. (IE瀏覽器)使用table-layout:fixed;強制table的寬度,多餘內容隱藏

<table style="table-layout:fixed" width="200">  <tr><td>abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss</td></tr></table>


  效果:隱藏多餘內容

  2.(IE瀏覽器)使用table-layout:fixed;強制table的寬度,內層td,th採用word-break : break-all;或者word-wrap : break-word ;換行

<table width="200" style="table-layout:fixed;">  <tr><td width="25%" style="word-break : break-all; ">abcdefghigklmnopqrstuvwxyz 1234567890</td><td style="word-wrap : break-word ;">abcdefghigklmnopqrstuvwxyz 1234567890</td></tr></table>

  效果:可以換行

  3. (IE瀏覽器)在td,th中嵌套p,p等採用上面提到的p,p的換行方法

  4.(Firefox瀏覽器)使用table-layout:fixed;強制table的寬度,內層td,th採用word-break : break-all;或者word-wrap : break-word ;換行,使用overflow:hidden;隱藏超出內容,這裡overflow:auto;無法起作用

<table style="table-layout:fixed" width="200">  <tr><td width="25%" style="word-break : break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td><td width="75%" style="word-wrap : break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td></tr></table>


  效果:隱藏多於內容

  5.(Firefox瀏覽器)在td,th中嵌套p,p等採用上面提到的對付Firefox的方法運行代碼框。最後,這種現象出現的幾率很小。

相關文章

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.