1

这是我为喊话箱准备的脚本 -

$result = mysql_query("SELECT * FROM `shoutbox` ORDER BY `id` DESC LIMIT 5");
while($r=mysql_fetch_array($result))
{
$time=$r["time"];
$id=$r["id"];
$message=$r["message"];
$name=$r["name"];
echo "<div style='position:relative;'>";
echo $name."&nbsp;&nbsp;&nbsp;".$message."<br/>".$time."<br/>"; 
echo "</div>";
}

问题是这段代码没有文本换行,我尝试添加文本换行但没有成功。当我输入没有空格的长文本时,文本会脱离 div。我怎样才能解决这个问题?而且,正如您可能已经注意到的那样,我已将消息数量限制为 5,DESC LIMIT 5我想知道如何使 div 可滚动,以便在向下滚动时显示超过 5 条消息之前的消息。

4

1 回答 1

0

它就像魅力一样,从“Aaron Bennett”收集

<style>
.wordwrap { 
   white-space: pre-wrap;      /* CSS3 */   
   white-space: -moz-pre-wrap; /* Firefox */    
   white-space: -pre-wrap;     /* Opera <7 */   
   white-space: -o-pre-wrap;   /* Opera 7 */    
   word-wrap: break-word;      /* IE */
}
</style>

<?php

echo "<div 
    style='width:150px; height:200px; overflow:auto;' class='wordwrap'>
        LongwordLongwordLongwordLongwordLongwordLongwordLongwordLongwordLongwordLongwordLongwordLongwordLongwordLongwordLongwordLongword
    </div>";    
?>

参考:https ://stackoverflow.com/a/1638824/2459296

于 2013-09-05T13:19:53.787 回答