和我们一起放飞理想吧!
  • 本栏最新文章
摄影专辑AD
  • 本栏推荐文章
当前位置:应用教程首页 >> xhtml+css >> 详细内容

CSS实现自动换行

2008-01-09 20:59:22    作者:newcss.cn    来源:新教程网    文字大小: |  | 
简介:大家都知道连续的英文或数字能是容器被撑大,不能根据容器的大小自动换行,下面是 CSS如何将他们换行的方法!对于divnewCss.cn^com1、(IE浏览器)white-space:normal; word-break:break-all;这里前者是遵循标准 ...
大家都知道连续的英文或数字能是容器被撑大,不能根据容器的大小自动换行,下面是 CSS如何将他们换行的方法!
对于div
newCss.cn^com
1、(IE浏览器)white-space:normal; word-break:break-all;这里前者是遵循标准。
#wrap{white-space:normal; width:200px; }
或者
#wrap{word-break:break-all;width:200px;}
<div >ddd1111111111111111111111111111111111</div> 中国新_教程网,为所有中国人会上网而努力
效果:可以实现换行
2、(Firefox浏览器)white-space:normal; word-break:break-all;overflow:hidden;同样的FF下也没有很好的实现方法,只能隐藏或者加滚动条,当然不加滚动条效果更好!
#wrap{white-space:normal; width:200px; overflow:auto;}
NEWCSS.CN
或者 newCss.cn^com
#wrap{word-break:break-all;width:200px; overflow:auto; }
<div >ddd1111111111111111111111111111111111111111</div> [中国新教程网]
效果:容器正常,内容隐藏
newCss.cn^com
对于table NEWCSS_CN
1、(IE浏览器)使用样式table-layout:fixed;
以下为引用的内容:
<style>
.tb{table-layout:fixed}
</style>
<table width="80">
<tr>
<td>abcdefghigklmnopqrstuvwxyz 1234567890
</td>
</tr>
</table>
效果:可以换行
2、(IE浏览器)使用样式table-layout:fixed与nowrap
以下为引用的内容:
<style>
.tb {table-layout:fixed}
</style>
中国新教程.网
<table width="80">
<tr>
<td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890
</td>
</tr>
</table> 中.国新教程网
Www_NEWCSS_CN
效果:可以换行 Www_NEWCSS_CN
3、(IE浏览器)在使用百分比固定td大小情况下使用样式table-layout:fixed与nowrap
以下为引用的内容:
<style>
.tb{table-layout:fixed}
</style>
<table width=80>
<tr>
<td width=25% nowrap>abcdefghigklmnopqrstuvwxyz 1234567890
</td>
<td nowrap>abcdefghigklmnopqrstuvwxyz 1234567890
</td>
</tr>
</table>
Www^newCss.cn^com
效果:两个td均正常换行 NEWCSS.CN
4、(Firefox浏览器)在使用百分比固定td大小情况下使用样式table-layout:fixed与nowrap,并且使用div 新.教程网
以下为引用的内容:
<style>
.tb {table-layout:fixed}
.td {overflow:hidden;}
</style>
<table width=80>
<tr>
<td width=25% nowrap>
<div>abcdefghigklmnopqrstuvwxyz 1234567890</div>
</td>
<td nowrap>
<div>abcdefghigklmnopqrstuvwxyz 1234567890</div>
</td>
</tr>
</table>这里单元格宽度一定要用百分比定义
NEWCSS_CN
效果:正常显示,但不能换行(注:在FF下还没有能使容器内容换行的好方法,只能用overflow将多出的内容隐藏,以免影响整体效果)
相关文章
绵阳网警