dongyou8701 2017-04-08 22:27
浏览 133
已采纳

PHP中的HTML <pre>自动换行不起作用

I've been working on a forum, and I've made everything work as it, and I tried wrapping to see if it works, basically that part of the code looks like this before the PHP I got some HTML style:

<style>
    pre {
        white-space: pre-wrap; 
        white-space: -moz-pre-wrap;
        white-space: -pre-wrap;
        white-space: -o-pre-wrap;
        word-wrap: break-word;    
        font-size: 20px;
        margin: 0% 8% 0px 8%; 
    }
</style>

And then after a bunch of MySQL things

echo '<table style="height: 21px;" width="100%">';
while($forumcomrow=mysqli_fetch_array($forumcomres))
{
    echo '<tr><td>some text</td><td><pre>Some Very Long Text From Mysql </pre></td></tr></br>';
}
echo '</table>';

I removed everything and just left the style for it and the echo for the table, when I echo just the pre tag, it wraps it at the end of the screen, but as soon as I put it in a table (size doesn't matter, even if I put the width of the table to 5px) it still goes 10 miles off the screen until it starts wrapping.

This is what happens:

This is what happens

On the picture above you can see one part of it, but the text goes off screen about 5x the length you can see on there, and only then starts wrapping

I have figured out what's giving it a problem, it will wrap the text if it has spaces ("aaaa aaa aaa aa aa") but if its one long word ("aaaaaaaaa") it won't wrap it, I don't know how to fix it, I've just figured out whats causing the problem.

  • 写回答

1条回答 默认 最新

  • dsbj66959 2017-04-08 23:08
    关注

    It is because of <br> tag at the end, I have faced the same problem some time ago. <br> get applied first for every time and then table gets wrapped.

    Remove <br> at the end

    echo '<tr><td>some text</td><td><pre>Some Very Long Text From Mysql </pre></td></tr>';
    

    and then it will work perfectly fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题