How to Wrap unspaces word for Opera Browser

牧云@^-^@ 提交于 2019-12-19 10:03:09

问题


I am currently testing this function in all browser using php.

<style>
#preview_desc{
    text-wrap: suppress;
    word-break: break-all;
    word-wrap: break-word; /* IE>=5.5 */
    white-space: -moz-pre-wrap; /* For Fx<=2 */   
    white-space: pre-wrap; /* Fx>3, Opera>8, Safari>3 */
    white-space: -o-pre-wrap; /* Opera 7 */
    white-space: pre-line;
    width:158px; 
    padding-left:5px; 
    padding-right:5px; 
    line-height:12px; 
    font-family:'Arial', Helvetica, sans-serif; 
    font-size:11px; 
    text-align:justify;
    background:#f30000;
}
</style>

<div id="preview_desc" 
class="adlookmsg_box">
Refeforotherapplicationandcontainasdhlsakfhnaiufalsdufgnaloskdufglkjblfasug
</div>

However only in Opera browser that not process the wrapping or the unspace word. Please if any can help with this. Tks

--Edited-- note: sorry bout this appereance.


回答1:


I am using Opera 10.10 also, I can regenerate your problem, but unfortunately I don't have good/proper answer, but a hack here. Do it If there is no other way. Put following codes to end of the document.

<script>
     x=document.getElementById("preview_desc");
     x.innerHTML=x.innerHTML.replace(/(.)/g,"$1\u200b");
</script>

It will put \u200b (Zero Width Space) character after every characters, so Opera would able to handle that..

UPDATE: Only add \u200b to long words, currently set as 10+, you may need to adjust it.

<script>
    x=document.getElementById("preview_desc");
    x.innerHTML=x.innerHTML.replace(/[\w]{10,}/g,function(x){return x.replace(/(.)/g,"$1\u200b");});
</script>


来源:https://stackoverflow.com/questions/1899453/how-to-wrap-unspaces-word-for-opera-browser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!