HTML 中的自动换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5852700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto break line in HTML
提问by Sigmund Grafia Avila
I've been doing a comment box and I have a problem after viewing my comment. All I want is to make my comment auto break line when it exceeds the container but what I've got right now is a straight line.
我一直在做一个评论框,我在查看我的评论后遇到了问题。我想要的只是让我的评论在超过容器时自动断线,但我现在得到的是一条直线。
For example:
例如:
tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
I hope my text can be like this:
我希望我的文字可以是这样的:
ttttttttttttt ttttttttttttt ttttttttttttt ttttttttttttt
What should I use to make my text auto break line?
我应该用什么来使我的文本自动换行?
回答by thirtydot
It sounds like you're after word-wrap: break-word
, and its cross-browser variants.
听起来您在追求word-wrap: break-word
及其跨浏览器变体。
See: https://developer.mozilla.org/en/CSS/white-space
请参阅:https: //developer.mozilla.org/en/CSS/white-space
selector {
word-wrap: break-word; /* IE 5.5-7 */
white-space: -moz-pre-wrap; /* Firefox 1.0-2.0 */
white-space: pre-wrap; /* current browsers */
}
回答by Nick Heiner
Try using string replacement:
尝试使用字符串替换:
$line_broken = str_replace("\n", "<br />", $comment);
But it's hard to tell without seeing your code.
但是如果没有看到你的代码就很难判断。
回答by Marty
Not sure how to auto-break your line without a chunk of PHP. You could consider using the CSS overflow: hidden;
or overflow: auto;
for your comment container.
不知道如何在没有大量 PHP 的情况下自动断行。您可以考虑使用 CSSoverflow: hidden;
或overflow: auto;
用于您的评论容器。