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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度