{"id":353,"date":"2009-01-09T08:52:31","date_gmt":"2009-01-09T00:52:31","guid":{"rendered":""},"modified":"2014-02-27T23:06:27","modified_gmt":"2014-02-27T15:06:27","slug":"word-wrap%e5%92%8cword-break%e8%a7%a3%e5%86%b3%e8%bf%9e%e7%bb%ad%e5%ad%97%e7%ac%a6%e8%87%aa%e5%8a%a8%e6%8d%a2%e8%a1%8c","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2009\/01\/09\/353.htm","title":{"rendered":"word-wrap\u548cword-break\u89e3\u51b3\u8fde\u7eed\u5b57\u7b26\u81ea\u52a8\u6362\u884c"},"content":{"rendered":"<p>\u6587\u672c\u7684\u6392\u7248\u4f9d\u636e\u8bed\u8a00\u7684\u4e0d\u540c\u4f1a\u6709\u4e00\u4e9b\u683c\u5f0f\u4e0a\u7684\u8981\u6c42\uff0c\u6bd4\u5982\u7b80\u4f53\u4e2d\u6587\u4e2d\u7c7b\u4f3c\u9017\u53f7\u3001\u5206\u53f7\u7b49\u6807\u70b9\u7b26\u53f7\u4e0d\u4f1a\u51fa\u73b0\u5728\u4e00\u884c\u7684\u5f00\u5934\uff0c\u5bf9\u4e8e\u82f1\u6587\u6765\u8bb2\u5c31\u662f\u4e00\u4e2a\u5b8c\u6574\u5355\u8bcd\u4e0d\u4f1a\u5728\u4e24\u884c\u663e\u793a\uff0c\u6d4f\u89c8\u5668\u4f1a\u4f9d\u636e\u7c7b\u4f3c\u8fd9\u6837\u7684\u539f\u5219\u6765\u663e\u793a\u6587\u672c\u3002\u4f46\u662f\u7531\u4e8e\u7f51\u9875\u6709\u5bbd\u5ea6\u9650\u5236\u7684\uff0c\u8fde\u7eed\u7684\u8d85\u957f\u7684\u5b57\u6bcd\u3001\u6570\u5b57\u6216\u6807\u70b9\u7b26\u53f7\u8d85\u51fa\u5176\u6240\u5728\u533a\u57df\u5bbd\u5ea6\u7684\u9650\u5236\u800c\u5bfc\u81f4\u5f71\u54cd\u9875\u9762\u89c6\u89c9\uff0c\u5982 \u4f8b1 \u6240\u793a\u3002\u8fd9\u4e2a\u95ee\u9898\u5728\u663e\u793a\u7528\u6237\u8f93\u5165\u4fe1\u606f\u65f6\u5c24\u4e3a\u7a81\u51fa\uff0c\u8fd9\u91cc\u5c31\u662f\u8981\u8bf4\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u5728CSS3\u8349\u6848\u4e2d\uff0c\u5bf9\u6587\u672c\u7684\u5904\u7406\u65b0\u589e\u4e86\u4e24\u4e2a\u65b0\u5c5e\u6027 word-wrap \u548c word-break \u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1a<\/p>\n<ol>\n<li>{word-wrap:break-word;} \uff1a\u4f9d\u7167\u4e9a\u6d32\u8bed\u8a00\u548c\u975e\u4e9a\u6d32\u8bed\u8a00\u7684\u6587\u672c\u89c4\u5219\uff0c\u5141\u8bb8\u5728\u5b57\u5185\u6362\u884c\uff0c\u4e14\u5141\u8bb8\u975e\u4e9a\u6d32\u8bed\u8a00\u6587\u672c\u884c\u7684\u4efb\u610f\u5b57\u5185\u65ad\u5f00<\/li>\n<li>{word-break:break-all;} \uff1a \u5185\u5bb9\u5c06\u5728\u8fb9\u754c\u5185\u6362\u884c\uff0c\u5982\u9700\u8981\u5219\u8bcd\u5185\u6362\u884c\uff08word-break\uff09\u4e5f\u884c\u53d1\u751f<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u662f\u5e38\u89c1\u6d4f\u89c8\u5668\u7684\u652f\u6301\u60c5\u51b5\uff1a<\/p>\n<table cellspacing=\"1\" cellpadding=\"1\" width=\"500\" border=\"1\" style=\"width: 500px; height: 63px\">\n<tbody>\n<tr>\n<td>\u3000<\/td>\n<td>IE<\/td>\n<td>Firefox<\/td>\n<td>Opera<\/td>\n<td>Safari\/Chrome<\/td>\n<\/tr>\n<tr>\n<td>{word-wrap:break-word;}<\/td>\n<td>td\u5143\u7d20\u9700\u8bbe\u7f6e\u5176\u5bbd\u5ea6<br \/>\n            \u89c1 \u4f8b4 \u548c \u4f8b5<\/td>\n<td>\u4e0d\u652f\u6301<\/td>\n<td>\u4e0d\u652f\u6301<\/td>\n<td>\u4e0d\u652f\u6301td\u5143\u7d20<br \/>\n            \u89c1 \u4f8b4 \u548c \u4f8b5<\/td>\n<\/tr>\n<tr>\n<td>{word-break:break-all;}<\/td>\n<td>\u4e0d\u652f\u6301\u8fde\u7eed\u7684\u7b26\u53f7<br \/>\n            \u89c1\u4f8b3<\/td>\n<td>\u4e0d\u652f\u6301<\/td>\n<td>\u4e0d\u652f\u6301<\/td>\n<td>\u652f\u6301<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7531\u4e8e{word-break:break-all;}\u5bfc\u81f4\u82f1\u6587\u548c\u6570\u5b57\u53ef\u8bfb\u6027\u4e25\u91cd\u4e0b\u964d\u4e14\u65e0\u6cd5\u4f7f\u8fde\u7eed\u7b26\u53f7\u6362\u884c\uff0c\u6240\u4ee5{word-wrap:break-word;}\u662f\u4e00\u4e2a\u76f8\u5bf9\u8f83\u597d\u7684\u9009\u62e9\u3002<\/p>\n<p>\u4f46\u9762\u5bf9\u6d4f\u89c8\u5668\u7684\u5982\u6b64\u7cdf\u7cd5\u652f\u6301\uff0c\u6240\u4ee5\u4e0d\u80fd\u4e0d\u501f\u52a9<a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/webdevelop.jzxue.com\/javascript-ajax\/\"><font color=\"#333333\">JavaScript<\/font><\/a>\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5373\u5f53\u6d4f\u89c8\u5668\u4e0d\u652f\u6301CSS\u89e3\u51b3\u65b9\u6848\u65f6\uff0c\u5728\u8fde\u7eed\u5b57\u7b26\u4e32\u7684\u9002\u5f53\u4f4d\u7f6e\u63d2\u5165&amp;#8203;\u5b57\u7b26\uff08\u5f53\u7136\u8fd8\u53ef\u4ee5\u7528&lt;wbr&gt;\u548c&amp;shy;\uff0c\u8fd9\u4e09\u4e2a\u5b57\u7b26\u5728\u6d4f\u89c8\u5668\u4e2d\u7684\u652f\u6301\u60c5\u51b5\u8bf7\u770bppk\u7684\u300aThe wbr tag\u300b\uff09\uff0c\u8fd9\u4e9b\u5b57\u7b26\u5199\u5728\u6d4f\u89c8\u5668\u4e2d\u4e0d\u4f1a\u663e\u793a\uff0c\u5374\u4f7f\u957f\u5b57\u7b26\u4e32\u6362\u884c\u3002\u5177\u4f53\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p><span class=\"code\">function fnBreakWordAll(o){<br \/>\nvar o = o || {},<br \/>\n&nbsp; iWord = o.word || 13,<br \/>\n&nbsp; iRe = o.re || &#8216;[a-zA-Z0-9]&#8217;,<br \/>\n&nbsp; bAll = o.all || false,<br \/>\n&nbsp; sClassName = o.className || &#8216;word-break-all&#8217;,<br \/>\n&nbsp; aEls = o.els || (function(){<br \/>\n&nbsp;&nbsp;&nbsp; var aEls = [],<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; aAllEls = document.getElementsByTagName(&#8216;*&#8217;),<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; re = new RegExp(&#8216;(?:^|\\\\s+)&#8217; + sClassName + &#8216;(?:\\\\s+|$)&#8217;);<br \/>\n&nbsp;&nbsp;&nbsp; for(var i =0,iLen = aAllEls.length; i &lt; iLen ; ++i){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(re.test(aAllEls[i].className)){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; aEls[aEls.length] = aAllEls[i];<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp; return aEls;<br \/>\n&nbsp; })() || [],<br \/>\n&nbsp; fnBreakWord = function(oEl){<br \/>\n&nbsp;&nbsp;&nbsp; \/\/ \u57fa\u4e8ehttp:\/\/www.hedgerwow.com\/360\/dhtml\/css-word-break.html\u4fee\u6539<br \/>\n&nbsp;&nbsp;&nbsp; if(!oEl || oEl.nodeType !== 1){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false;<br \/>\n&nbsp;&nbsp;&nbsp; }else if(oEl.currentStyle &amp;&amp; typeof oEl.currentStyle.wordWrap===&#8217;string&#8217;){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; breakWord = function(oEl){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oEl.runtimeStyle.wordWrap = &#8216;break-word&#8217;;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return breakWord(oEl);<br \/>\n&nbsp;&nbsp;&nbsp; }else if(document.createTreeWalker){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var trim = function&nbsp; (str) {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str = str.replace(\/^\\s\\s*\/, &#8221;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var ws = \/\\s\/,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = str.length;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (ws.test(str.charAt(&#8211;i)));<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return str.slice(0, i + 1);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; breakWord = function(oEl){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var dWalker=document.createTreeWalker(oEl,NodeFilter.SHOW_TEXT,null,false);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var node,s,c = String.fromCharCode(&#8216;8203&#8217;),<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/re = \/([a-zA-Z0-9]{0,13})\/;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; re = new RegExp(&#8216;(&#8216;+ iRe +'{0,&#8217; + iWord + &#8216;})&#8217;);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (dWalker.nextNode()){<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node = dWalker.currentNode;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = trim(node.nodeValue).split(re).join(c);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node.nodeValue = s;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return breakWord(oEl);<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp; };<br \/>\nfor(var i=0,n=aEls.length; i&lt;n; ++i){<br \/>\n&nbsp; var sUa = navigator.userAgent,<br \/>\n&nbsp;&nbsp;&nbsp; sTn = aEls[i].tagName.toLowerCase() ;<br \/>\n&nbsp; if((\/Opera\/).test(sUa) || (\/Firefox\/).test(sUa) || ((\/KHTML\/).test(sUa) &amp;&amp;<br \/>\n&nbsp; (sTn === &#8216;td&#8217; || sTn === &#8216;th&#8217;)) || bAll){<br \/>\n&nbsp;&nbsp;&nbsp; fnBreakWord(aEls[i]);<br \/>\n&nbsp; }<br \/>\n}<br \/>\n}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>fnWordBreakAll\u51fd\u6570\u63d0\u4f9b\u4e00\u4e9b\u5b9a\u5236\u53c2\u6570\uff0c\u4f7f\u7528\u65b9\u6cd5\u548c\u53c2\u6570\u542b\u4e49\u5982\u4e0b\uff1a<\/p>\n<p><span class=\"code\">fnWordBreakAll({word:15,re:'[\\\\w]&#8217;,all:true});<\/span><\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<th>\u53c2\u6570<\/th>\n<th>\u503c<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<tr>\n<th>word<\/th>\n<td>\u6b63\u6574\u6570\uff0c\u9ed8\u8ba4\u662f13<\/td>\n<td>\u5728\u8fd9\u4e2a\u5b57\u6570\u5185\u7684\u5355\u8bcd\u4e0d\u4f1a\u88ab\u63d2\u5165\\u8203\uff0c\u5370\u8c61\u4e2d\u8d85\u8fc713\u4e2a\u5b57\u6bcd\u7684\u5355\u8bcd\u4e0d\u591a\uff0c\u8fd9\u53ef\u4ee5\u4fdd\u8bc1\u7edd\u5927\u90e8\u5206\u5355\u8bcd\u4e0d\u4f1a\u88ab\u6253\u788e<\/td>\n<\/tr>\n<tr>\n<th>re<\/th>\n<td>\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u9ed8\u8ba4[a-zA-Z0-9]<\/td>\n<td>\u5355\u8bcd\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7528\u4ee5\u786e\u5b9a\u4e00\u4e2a\u5355\u8bcd\u662f\u54ea\u4e9b\u5b57\u7b26\u7ec4\u6210\uff0c\u6ce8\u610f\\\u7684\u8f6c\u4e49<\/td>\n<\/tr>\n<tr>\n<th>all<\/th>\n<td>\u5e03\u5c14\u503c\uff0c\u9ed8\u8ba4false<\/td>\n<td>\u786e\u5b9a\u662f\u5426\u5728\u6240\u6709\u7684\u6d4f\u89c8\u5668\u4e2d\u6267\u884c\uff0c\u9ed8\u8ba4\u5728Opera\u548cFirefox\uff0c\u4ee5\u53ca\u5f53class\u5e94\u7528\u5728th\u6216td\u7684Safari\u4e0a\u6267\u884c\uff0c\u8fd9\u4e2a\u4e3b\u8981\u7528\u5728.word-break-all\u6ca1\u6709\u5b9a\u4e49\u65f6\uff0c\u4f1a\u5bf9IE\u52a0\u4e0a\u6837\u5f0f<\/td>\n<\/tr>\n<tr>\n<th>className<\/th>\n<td>\u5408\u6cd5class\u540d\uff0c\u9ed8\u8ba4word-break-all<\/td>\n<td>\u6267\u884c\u51fd\u6570\u7684\u5143\u7d20\u5bf9\u5e94\u5c5e\u6027\u540d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u4e2a\u51fd\u6570\u7684\u6838\u5fc3\u90e8\u5206\u4fee\u6539\u81ea<strong>Hedger Wang<\/strong> \u6574\u7406\u4e86\u4e00\u4e2aJavaScript\u89e3\u51b3\u65b9\u6848\u300aCross Browser Word Breaker\u300b\uff0c\u5176\u5229\u7528 document.createTreeWalker \u548c <strong>split<\/strong> \u65b9\u6cd5\u7ed9\u975eIE\u6d4f\u89c8\u5668\u7684\u6bcf\u4e2a\u5b57\u7b26\u95f4\u52a0\u5165\u4e86<strong>&amp;#8203;<\/strong> \uff0c\u5b83\u7528\u5728\u7eaf\u4e2d\u6587\u6587\u672c\u57fa\u672c\u4e0a\u6ca1\u6709\u4ec0\u4e48\u95ee\u9898\uff0c\u4f46\u662f\u5982\u679c\u4f60\u4ed4\u7ec6\u89c2\u5bdf\u4ed6\u7ed9\u51fa\u7684\u4f8b\u5b50\u5c31\u4f1a\u53d1\u73b0\u6587\u672c\u4e2d\u6709\u82f1\u6587\u6216\u6570\u5b57\u65f6\uff0c\u867d\u7136\u89e3\u51b3\u4e86\u6362\u884c\u95ee\u9898\uff0c\u4f46\u662f\u4f7f\u6587\u672c\u96be\u4ee5\u9605\u8bfb\uff0c\u4e14\u589e\u5927\u4e86\u5b57\u7b26\u95f4\u7684\u95f4\u8ddd\uff0c\u6240\u4ee5\u6211\u5728\u6b64\u57fa\u7840\u4e0a\u505a\u4e86\u4e0a\u9762\u7684\u6539\u8fdb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u672c\u7684\u6392\u7248\u4f9d\u636e\u8bed\u8a00\u7684\u4e0d\u540c\u4f1a\u6709\u4e00\u4e9b\u683c\u5f0f\u4e0a\u7684\u8981\u6c42\uff0c\u6bd4\u5982\u7b80\u4f53\u4e2d\u6587\u4e2d\u7c7b\u4f3c\u9017\u53f7\u3001\u5206\u53f7\u7b49\u6807\u70b9\u7b26\u53f7\u4e0d\u4f1a\u51fa\u73b0\u5728\u4e00\u884c\u7684\u5f00\u5934\uff0c\u5bf9\u4e8e\u82f1\u6587\u6765\u8bb2\u5c31\u662f\u4e00\u4e2a\u5b8c\u6574\u5355\u8bcd\u4e0d\u4f1a\u5728\u4e24\u884c\u663e\u793a\uff0c\u6d4f\u89c8\u5668\u4f1a\u4f9d\u636e\u7c7b\u4f3c\u8fd9\u6837\u7684\u539f\u5219\u6765\u663e\u793a\u6587\u672c\u3002\u4f46\u662f\u7531\u4e8e\u7f51\u9875\u6709\u5bbd\u5ea6\u9650\u5236\u7684\uff0c\u8fde\u7eed\u7684\u8d85\u957f\u7684\u5b57\u6bcd\u3001\u6570\u5b57\u6216\u6807&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-353","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=353"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/353\/revisions"}],"predecessor-version":[{"id":66231,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/353\/revisions\/66231"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=353"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=353"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}