简体   繁体   English

不能打断一个长字符串/文本,它超过了 html div 的宽度

[英]Can't break a long string/text, it exceeds the width of html div

<div id="id_div_comments"><p>body4qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq</p></div><br/><br/>
</div>

The css file: css 文件:

div#id_div_comments {
    width: 400px;
}

But the string/texts exceeds the division width.但是字符串/文本超出了分割宽度。 What can i do to break the texts when it reaches the width of the division?当文本达到分隔线的宽度时,我该怎么做才能打破文本?

wirte this in your css word-wrap:break-word;在你的 css word-wrap:break-word;写入word-wrap:break-word; css: css:

#id_div_comments p{
 word-wrap:break-word;
}

Try this code:试试这个代码:

#id_div_comments p{
 white-space:normal;
}

The accepted answer doesn't work for me接受的答案对我不起作用

After seaching around, the following css actually works四处搜索后,以下css实际上有效

#id_div_comments p{
 overflow: hidden;
}

Just trust me相信我

在此处输入图片说明

Old question but no correct answer, for long text this should work老问题但没有正确答案,对于长文本,这应该有效

#id_div_comments p{
 word-break: break-all;
}
#id_div_comments p{
 white-space:nowrap;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM