自动换行适用于没有任何特殊字符的长字符串。我想在URL上使用它。而不是填充连续的所有列,文本在遇到特殊字符(如=,&)时会转到下一行。有没有其他方法来解决这个问题? HTML:
<div style="word-wrap: break-word; width:100px;" id="foo"></div>
JS:
var div = document.getElementById("foo");
div.innerHTML = "https://www.google.co.in/search?q=hello+world&ie=utf-8&oe=utf-8&gws_rd=cr&ei=aNqUVZ7ZK4KVuATI3IGIDg";
JS小提琴here。
PS:溢出不是很好!
答案 0 :(得分:7)
尝试使用word-break: break-all;
var div = document.getElementById("foo");
div.innerHTML = "https://www.google.co.in/search?q=hello+world&ie=utf-8&oe=utf-8&gws_rd=cr&ei=aNqUVZ7ZK4KVuATI3IGIDg";
&#13;
#foo{
word-break: break-all;
}
&#13;
<div style="width:100px;" id="foo">
</div>
&#13;