HTML 中自动换行

问题描述 投票:0回答:6

我一直在做评论框,在查看我的评论后遇到了问题。我想要的只是让我的评论在超出容器时自动断线,但我现在得到的是一条直线。

例如:

TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

我希望我的文字可以是这样的:

tttttttttttttttttttttttttttttttttttttt ttttttttttttttttttttttttttttttttttttt ttttttttttttttttttttttttttttttttttttt tttttttttttt ttttttttttttttttttttttttt

我应该用什么来让我的文本自动换行?

html css
6个回答
48
投票
听起来您正在寻找

word-wrap: break-word

 及其跨浏览器变体。

请参阅:

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 */ }

演示:

http://jsfiddle.net/MCj6s/


2
投票
尝试使用字符串替换:

$line_broken = str_replace("\n", "<br />", $comment);

但是如果不看到你的代码就很难判断。


1
投票
使用 HTML 的解决方案:标签

<wbr>

 标记“建议的换行符”,也就是单词中可以进行换行的位置。

MySuperLongWord

 默认情况下不会有换行符。

My<wbr>Super<wbr>Long<wbr>Word
 必要时会在 
<wbr>
 处换行。


0
投票
不知道如何在没有 PHP 块的情况下自动断行。您可以考虑使用 CSS

overflow: hidden;

overflow: auto;
 作为评论容器。


0
投票
在你想要换行的地方使用

<br>


    


0
投票
更改为 ,它会如你所愿地崩溃

© www.soinside.com 2019 - 2024. All rights reserved.