css中强制换行word-break、word-wrap、white-space区别实例说明
(编辑:jimmy 日期: 2025/2/26 浏览:3 次 )
测试用的HTML代码
复制代码代码如下:
<div class="c1">safjaskflasjfklsajfklasjflksajflksjflkasfdsafdsfksafj</div>
<div class=c1>This is all English. This is all English. This is all English.</div>
<div class=c1>全是中文的情况。全是中文的情况。全是中文的情况。</div>
<div class=c1>中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.</div>
1.
复制代码代码如下:.c1{ width:300px;word-break:normal;border:1px solid red;}


如果内容是长英文字符串的话,IE6会把容器撑开,其他浏览器只会溢出,不会撑开
2.
复制代码代码如下:.c1{ width:300px;word-break:break-all;border:1px solid red;}


长英文字符串在火狐下不能换行
3.
复制代码代码如下:.c1{ width:300px;word-break:keep-all;border:1px solid red;}

IE6下,英文长字符创和中文长句会撑开容器,IE7、IE8直接溢出,火狐下只有长英文字符串会溢出。
4.
复制代码代码如下:.c1{ width:300px;word-wrap:normal;border:1px solid red;}这个跟第一种情况一样
5.
复制代码代码如下:.c1{ width:300px;word-wrap:break-word;border:1px solid red;}

所有浏览器都换行了
6.
复制代码代码如下:.c1{ width:300px;white-space:normal;border:1px solid red;}跟第一种情况一样
7.
复制代码代码如下:.c1{ width:300px;white-space:pre;border:1px solid red;}


IE6下全部撑开,IE7、IE8、Firefox下全部溢出
8.
复制代码代码如下:.c1{ width:300px;white-space:nowrap;border:1px solid red;}与7相同
复制代码代码如下:
<div class="c1">safjaskflasjfklsajfklasjflksajflksjflkasfdsafdsfksafj</div>
<div class=c1>This is all English. This is all English. This is all English.</div>
<div class=c1>全是中文的情况。全是中文的情况。全是中文的情况。</div>
<div class=c1>中英文混排的情况。Chinese and English. 中英文混排的情况。Chinese and English.</div>
1.
复制代码代码如下:.c1{ width:300px;word-break:normal;border:1px solid red;}


如果内容是长英文字符串的话,IE6会把容器撑开,其他浏览器只会溢出,不会撑开
2.
复制代码代码如下:.c1{ width:300px;word-break:break-all;border:1px solid red;}


长英文字符串在火狐下不能换行
3.
复制代码代码如下:.c1{ width:300px;word-break:keep-all;border:1px solid red;}



IE6下,英文长字符创和中文长句会撑开容器,IE7、IE8直接溢出,火狐下只有长英文字符串会溢出。
4.
复制代码代码如下:.c1{ width:300px;word-wrap:normal;border:1px solid red;}这个跟第一种情况一样
5.
复制代码代码如下:.c1{ width:300px;word-wrap:break-word;border:1px solid red;}

所有浏览器都换行了
6.
复制代码代码如下:.c1{ width:300px;white-space:normal;border:1px solid red;}跟第一种情况一样
7.
复制代码代码如下:.c1{ width:300px;white-space:pre;border:1px solid red;}


IE6下全部撑开,IE7、IE8、Firefox下全部溢出
8.
复制代码代码如下:.c1{ width:300px;white-space:nowrap;border:1px solid red;}与7相同
下一篇:牛人也得看的15个CSS技巧(提高网页效率)