使用百分比固定的table大小中td内容自动换行问题

 连续的英文或数字能是容器被撑大,不能根据容器的大小自动换行,对于Div和table以及不同的浏览器,实现css自动换行的方法都稍有不同,下面分别介绍:

      对于div

  1.(IE浏览器)white-space:normal; word-break:break-all;这里前者是遵循标准。

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

  效果:可以实现自动换行

  2.(Firefox浏览器)white-space:normal; word-break:break-all;overflow:hidden;同样的FF下也没有很好的实现方法,只能隐藏或者加滚动条,当然不加滚动条效果更好!

以下是引用片段:
#wrap{white-space:normal; 200px; overflow:auto;} 
或者 
#wrap{word-break:break-all;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>

原文地址:https://www.cnblogs.com/zyn1990/p/3981069.html