[英]Keeping text within div: Both newline, white-space and long words
Say I have the following string: 说我有以下字符串:
"This line should always break on newline \n, spaces if it is about to overflow and veryLongLinksThatDoNotFitInsideTheDiv"
I want it to break on: 我希望它断开:
Based on text flowing out of div , I tried: 基于从div流出的文本 ,我尝试了:
<div id="log" style="word-break: break-all"></div>
<!-- <div id="log" style="word-wrap: break-word"></div> -->
<!-- <div id="log" style="white-space: pre-line"></div> -->
<!-- <div id="log" style="white-space: pre; word-break: break-all"></div> -->
But I can not get all 3 (nor 4) criteria met. 但是我不能满足所有3个(也没有4个)标准。
Fiddle: https://jsfiddle.net/6kq14cfc/ 小提琴: https : //jsfiddle.net/6kq14cfc/
You can use 您可以使用
<div id="log" style="overflow-wrap: break-word;white-space: pre-wrap;"></div>
or 要么
<div id="log" style="word-wrap: break-word;word-break: normal;white-space: pre-wrap;"></div>
I think you're answer lies in replacing "\\n" with "<br />". 我认为您的答案在于将“ \\ n”替换为“ <br />”。 HTML does not recognize new line characters - it needs the <br /> tag instead.
HTML无法识别换行符-它需要<br />标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.