欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

css控制文字自動換行的實現(xiàn)方法

  發(fā)布時間:2016-10-12 10:18:32   作者:佚名   我要評論
下面小編就為大家?guī)硪黄猚ss控制文字自動換行的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

自動換行問題,正常字符的換行是比較合理的,而連續(xù)的數字和英文字符常常將容器撐大,挺讓人頭疼,下面介紹的是CSS如何實現(xiàn)換行的方法

對于div,p等塊級元素

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

html

正常文字的換行(亞洲文字和非亞洲文字)元素擁有默認的white-space:normal,當定義

css

CSS Code復制內容到剪貼板
  1. #wrap{whitewhite-space:normalwidth:200px; }   
1.(IE瀏覽器)連續(xù)的英文字符和阿拉伯數字,使用word-wrap : break-word ;或者word-break:break-all;實現(xiàn)強制斷行

CSS Code復制內容到剪貼板
  1. #wrap{word-break:break-allwidth:200px;}   
或者

CSS Code復制內容到剪貼板
  1. #wrap{word-wrap:break-word; width:200px;}   
  2.   
  3. abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111   

效果:可以實現(xiàn)換行

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

CSS Code復制內容到剪貼板
  1. #wrap  
  2.   
  3. {word-break:break-allwidth:200pxoverflow:auto;}   
  4.   
  5. abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111   

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

對于table

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

XML/HTML Code復制內容到剪貼板
  1. <table style="table-layout:fixed" width="200">  
  2. <tr>  
  3. <td>abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss   
  4. </td>  
  5. </tr>  
  6. </table>  

效果:隱藏多余內容

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

XML/HTML Code復制內容到剪貼板
  1. <table width="200" style="table-layout:fixed;">    
  2.     <tr>    
  3.         <td width="25%" style="word-break : break-all; ">abcdefghigklmnopqrstuvwxyz 1234567890      
  4.         </td>    
  5.         <td style="word-wrap : break-word ;">abcdefghigklmnopqrstuvwxyz 1234567890   
  6.         </td>    
  7.     </tr>    
  8. </table>  

效果:可以換行

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

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

XML/HTML Code復制內容到剪貼板
  1. <table style="table-layout:fixed" width="200">  
  2. <tr>  
  3. <td width="25%"  style="word-break : break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>  
  4. <td width="75%" style="word-wrap : break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>  
  5. </tr>  
  6. </table>  

效果:隱藏多于內容

5.(Firefox瀏覽器) 在td,th中嵌套div,p等采用上面提到的對付Firefox的方法
運行代碼框
最后,這種現(xiàn)象出現(xiàn)的幾率很小,但是不能排除網友的惡搞。如果

有什么問題請到在下面留言

下面是提到的例子的效果

XML/HTML Code復制內容到剪貼板
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5. <title>字符換行   
  6.     
  7. </title>  
  8. <style type="text/css">  
  9. table,td,th,div { border:1px green solid;}   
  10. code { font-family:"Courier New", Courier, monospace;}   
  11.     
  12. </style>  
  13. </head>  
  14. <body>  
  15. <h1><code>div</code></h1>  
  16. <h1><code>All white-space:normal;</code></h1>  
  17. <div style="white-space:normal; width:200px;">Wordwrap still occurs in a td element that    
  18. has its WIDTH attribute set to a value smaller than the unwrapped content of the cell,    
  19. even if the noWrap property is set to true. Therefore, the WIDTH attribute takes    
  20. precedence over the noWrap property in this scenario</div>  
  21.     
  22. <h1><code>IE  word-wrap : break-word ;</code></h1>  
  23. <div style="word-wrap : break-word ; width:200px;">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>  
  24. <h1><code>IE  word-break:break-all;</code></h1>  
  25. <div style="word-break:break-all;width:200px;">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>  
  26.     
  27. <h1><code>Firefox/ word-break:break-all; overflow:auto;</code></h1>  
  28. <div style="word-break:break-all; width:200px; overflow:auto;">abcdefghijklmnabcdefghijklmnabcdefghijkl   
  29. mn111111111</div>  
  30. <h1><code>table</code></h1>  
  31. <h1><code>table-layout:fixed;</code></h1>  
  32. <table style="table-layout:fixed" width="200">  
  33. <tr>  
  34. <td>abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss</td>  
  35. </tr>  
  36. </table>  
  37. <h1><code>table-layout:fixed; word-break : break-all; word-wrap : break-word ;</code></h1>  
  38. <table width="200" style="table-layout:fixed;">  
  39. <tr>  
  40. <td width="25%" style="word-break : break-all; ">abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss</td>  
  41. <td style="word-wrap : break-word ;">abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss</td>  
  42. </tr>  
  43. </table>  
  44. <h1><code>FF  table-layout:fixed; overflow:hidden;</code></h1>  
  45. <table style="table-layout:fixed" width="200">  
  46. <tr>  
  47. <td width="25%"  style="word-break : break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>  
  48. <td width="75%" style="word-wrap : break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>  
  49. </tr>  
  50. </table>  
  51. </body>  
  52. </html>  

以上就是小編為大家?guī)淼腸ss控制文字自動換行的實現(xiàn)方法全部內容了,希望大家多多支持腳本之家~

相關文章

最新評論