使用百分比固定的table大小中td內容自動換行問題


 連續的英文或數字能是容器被撐大,不能根據容器的大小自動換行,對於Div和table以及不同的瀏覽器,實現css自動換行的方法都稍有不同,下面分別介紹:

      對於div

  1.(IE瀏覽器)white-space:normal; word-break:break-all;這里前者是遵循標准。

 

以下是引用片段:
#wrap{white-space:normal; width:200px; } 
或者 
#wrap{word-break:break-all;width:200px;} 
<div id="wrap">ddd111111111111111111111111111111</div>

 

  效果:可以實現自動換行

  2.(Firefox瀏覽器)white-space:normal; word-break:break-all;overflow:hidden;同樣的FF下也沒有很好的實現方法,只能隱藏或者加滾動條,當然不加滾動條效果更好!

 

以下是引用片段:
#wrap{white-space:normal; width:200px; overflow:auto;} 
或者 
#wrap{word-break:break-all;width:200px; overflow:auto; } 
<div id="wrap">ddd1111111111111111111111111111111111111111</div>

 

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

      對於table

  1. (IE瀏覽器)使用樣式table-layout:fixed;

 

以下是引用片段:
<style> 
.tb{table-layout:fixed} 
</style> 
<table class="tbl" width="80"> 
<tr><td> 
abcdefghigklmnopqrstuvwxyz 1234567890 
</td></tr> 
</table>

 

  效果:可以自動換行

  2.(IE瀏覽器)使用樣式

 

以下是引用片段:
<style> 
.tb {table-layout:fixed} 
</style> 
<table class="tb" width="80"><tr><td nowrap> 
abcdefghigklmnopqrstuvwxyz 1234567890 
</td></tr> 
</table>

 

  效果:可以自動換行

  3. (IE瀏覽器)在使用百分比固定td大小情況下使用樣式table-layout:fixed與nowrap

 

以下是引用片段:
<style> 
.tb{table-layout:fixed} 

.tdl{

white-space:normal;

word-break:break-all;

overflow: auto;

}
</style> 
<table class="tb" width=="100%"> 
<tr> 
<td width=25% nowrap="nowrap" class="tdl"> 
abcdefghigklmnopqrstuvwxyz 1234567890 
</td> 
</tr> 
</table>

 

  效果:兩個td均正常自動換行

  4.(Firefox瀏覽器)在使用百分比固定td大小情況下使用樣式table-layout:fixed與nowrap,並且使用div

 

以下是引用片段:
<style> 
.tbl {table-layout:fixed} 

.divstyle{

white-space:normal;

word-break:break-all;

overflow: auto;

}
</style> 
<table class="tbl" width="100%"> 
<tr>

<td width=25%  nowrap="nowrap"> 

      <div class="divstyle" >abcdefghigklmnopqrstuvwxyz 1234567890</div> 
  </td> 

</tr> 
</table>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM