<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "HTTP://www.w3.org/tr/xhtml1/dtd/ xhtml1-transitional.dtd">
<html xmlns="HTTP://www.jzread.com/1999/xhtml">
<head>
< meta HTTP-equiv="content-type" content="text/html; charset=utf-8" />
<title>firefox-break-word</title>
<style type="text/css">
<!- -/*--><! [cdata[/*><!--*/
#break {border:1px solid #ccc;padding:.4em .8em;width:200px;word-wrap:break-word; word-break:break-all;}
/*]] >*/-->
</style>
</head>
<body>
<div id="break">
if there were less sympathy in the world, there would be less trouble in the world. ( o. wilde )
</div>
<script>
function tobreakword(intlen){
var obj=document.getelementbyid ("ff");
var strcontent=obj.innerhtml;
var strtemp="";
while(strcontent.length>intlen){
strtemp+=strcontent.substr(0,intlen)+"
";
strcontent=strcontent.substr(intlen,strcontent.length);
}
strtemp+="
"+strcontent;
obj.innerhtml=strtemp;
}
if(document.getelementbyid && !document.all) tobreakword(37)
</script>
1. (ie瀏覽器)連續的英文字元和阿拉伯數位,使用word-wrap : break-word ;或者word-break:break-all;實現強制斷行
#wrap{word-break:break-all; width:200px;}
或者
#wrap{word-wrap:break-word; width:200px;}
<div id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>
效果:可以實現換行
2.(firefox瀏覽器)連續的英文字元和阿拉伯數位的斷行,firefox的所有版本的沒有解決這個問題,我們只有讓超出邊界的字元隱藏或者,給容器添加捲軸
#wrap{word-break:break-all; width:200px; overflow:auto;}
<div id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>
效果:容器正常,內容隱藏
</body>
</html>