ie firefox 下 css控制英文換行

來源:互聯網
上載者:User

一:
ie:
word-wrap:break-word;
word-break:break-all;

firefox:
js控制
   <div id="ff" style="word-break:break-all; </div>
   <script type="text/javascript">
    //  <![CDATA[
    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(120)
    // ]]>
    </script>

二:
ie,firefox:

<style type="text/css">
.wordwrap
{
     word-wrap:break-word;
     word-break:break-all;
    -moz-binding: url('./wordwrap.xml#wordwrap');
     overflow: hidden;
}
</style>

其中裡面有個wordwrap.xml,這個檔案的內容如下:

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://www.mozilla.org/xbl" xmlns:html="http://www.w3.org/1999/xhtml">

<binding id="wordwrap" applyauthorstyles="false">

    <implementation>
        <constructor>
            //<![CDATA[
           
            var elem = this;

            elem.addEventListener('overflow',
                function()
                {
                    var exp = /<&#8203;\/*[&#8203;_\s="'\w]+>/g;
                   
                    var txt = elem.innerHTML;
                    var chars = txt.split('');
                    var newTxt = chars.join('&#8203;');                   
                    newTxt = newTxt.replace(exp, reconstructTag);                   
                    elem.innerHTML = newTxt;
                },false);
               
                function reconstructTag(_tag)
                {
                    return _tag.replace(/&#8203;/g, '');
                }

            //]]>
        </constructor>
    </implementation>
</binding>

</bindings>
<!-- Web2 -->

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.