css 自动换行

参考地址:http://blog.csdn.net/shehun1/article/details/8545934


那年,那月,那日,那时,发现了一个Bug,英文字符在某些情况下没有自动换行。效果图如下:



对于这种大大影响界面美观的代码,肯定是在不同浏览器下不同文件有不同的编码方式所致,为解决此问题,本人先在不同浏览器下使用相同的代码进行测试,结果发现各种诡异的问题。最终,唯有一种CSS样式可以适应所有的浏览器,它就是下面的代码。

  1. <SPAN style="FONT-SIZE: 18px">width:200px;
  2. word-wrap:break-word ;
  3. word-break: break-all;</SPAN>
width:200px;
word-wrap:break-word ;
word-break: break-all;

上面的代码出现的效果图如下:



为了方便各位博客针对此代码进行测试,本人写了一个测试文件,感兴趣的朋友,可以免费试用~~

  1. <SPAN style="FONT-SIZE: 18px"><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=GB2312">
  5. <title>测试中英文换行问题</title>
  6. </head>
  7. <body>
  8. <div>
  9. <h1 style="font-weight:bold">用户自以为是的换行:style="width:200px"</h1>
  10. <div style="width:200px;">
  11. <span style="color:blue;font-weight:bold">宽度为200px下的中文测试数据:</span>
  12. <span style="width:200px">长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长</span>
  13. <br>
  14. <span style="color:blue;font-weight:bold">宽度为200px下的英文测试数据:</span>
  15. <span style="width:200px">LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong</span>
  16. <br>
  17. <span style="color:blue;font-weight:bold">宽度为200px下的特殊字符测试数据:</span>
  18. <span style="width:200px">长长长长长长长长长长长长长长长长长长长长长长长长............................................</span>
  19. <br>
  20. <span style="color:blue;font-weight:bold">宽度为200px下的数字测试数据:</span>
  21. <span style="width:200px">000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</span>
  22. </div>
  23. <h1 style="font-weight:bold">用户自以为是的换行:style="width:200px;word-wrap:break-word ;"</h1>
  24. <div style="width:200px;word-wrap:break-word ;">
  25. <span style="color:blue">宽度为200px下的中文测试数据:</span>
  26. <span>长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长</span>
  27. <br>
  28. <span style="color:blue">宽度为200px下的英文测试数据:</span>
  29. <span>LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong</span>
  30. <br>
  31. <span style="color:blue">宽度为200px下的特殊字符测试数据:</span>
  32. <span>长长长长长长长长长长长长长长长长长长长长长长长长..............................................</span>
  33. <br>
  34. <span style="color:blue">宽度为200px下的数字测试数据:</span>
  35. <span>000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</span>
  36. </div>
  37. <h1 style="font-weight:bold">用户自以为是的换行:style="width:200px;word-wrap:break-word ;word-break: break-all;"</h1>
  38. <div style="width:200px;word-wrap:break-word ;word-break: break-all;">
  39. <span style="color:blue">宽度为200px下的中文测试数据:</span>
  40. <span>长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长</span>
  41. <br>
  42. <span style="color:blue">宽度为200px下的英文测试数据:</span>
  43. <span>LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong</span>
  44. <br>
  45. <span style="color:blue">宽度为200px下的特殊字符测试数据:</span>
  46. <span>长长长长长长长长长长长长长长长长长长长长长长长长..............................................</span>
  47. <br>
  48. <span style="color:blue">宽度为200px下的数字测试数据:</span>
  49. <span>000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</span>
  50. </div>
  51. </div>
  52. </body>
  53. </html></SPAN>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>测试中英文换行问题</title>
</head>
<body>
	<div>
		<h1 style="font-weight:bold">用户自以为是的换行:style="width:200px"</h1>
		<div style="width:200px;">
			<span style="color:blue;font-weight:bold">宽度为200px下的中文测试数据:</span>
			<span style="width:200px">长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长</span>
			<br>
			<span style="color:blue;font-weight:bold">宽度为200px下的英文测试数据:</span>
			<span style="width:200px">LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong</span>
			<br>
			<span style="color:blue;font-weight:bold">宽度为200px下的特殊字符测试数据:</span>
			<span style="width:200px">长长长长长长长长长长长长长长长长长长长长长长长长............................................</span>
			<br>
			<span style="color:blue;font-weight:bold">宽度为200px下的数字测试数据:</span>
			<span style="width:200px">000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</span>
		</div>
		<h1 style="font-weight:bold">用户自以为是的换行:style="width:200px;word-wrap:break-word ;"</h1>
		<div style="width:200px;word-wrap:break-word ;">
			<span style="color:blue">宽度为200px下的中文测试数据:</span>
			<span>长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长</span>
			<br>
			<span style="color:blue">宽度为200px下的英文测试数据:</span>
			<span>LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong</span>
			<br>
			<span style="color:blue">宽度为200px下的特殊字符测试数据:</span>
			<span>长长长长长长长长长长长长长长长长长长长长长长长长..............................................</span>
			<br>
			<span style="color:blue">宽度为200px下的数字测试数据:</span>
			<span>000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</span>
		</div>
		<h1 style="font-weight:bold">用户自以为是的换行:style="width:200px;word-wrap:break-word ;word-break: break-all;"</h1>
		<div style="width:200px;word-wrap:break-word ;word-break: break-all;">
			<span style="color:blue">宽度为200px下的中文测试数据:</span>
			<span>长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长长</span>
			<br>
			<span style="color:blue">宽度为200px下的英文测试数据:</span>
			<span>LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong</span>
			<br>
			<span style="color:blue">宽度为200px下的特殊字符测试数据:</span>
			<span>长长长长长长长长长长长长长长长长长长长长长长长长..............................................</span>
			<br>
			<span style="color:blue">宽度为200px下的数字测试数据:</span>
			<span>000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</span>
		</div>
	</div>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值