这是我用于shoutbox的脚本 -
$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." ".$message."<br/>".$time."<br/>";
echo "</div>";
}
问题是这段代码没有文本换行,我尝试添加文本换行但没有成功。当我输入没有空格的长文本时,文本会从div中删除。我怎样才能解决这个问题?并且,正如您可能已经注意到我使用DESC LIMIT 5
将消息数限制为5我想知道如何使div可滚动,以便在向下滚动时显示超过5条消息的早期消息。
答案 0 :(得分: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>";
?>