Div标签不包含内容

时间:2010-08-11 20:28:15

标签: php css expand

我已经创建了一个表单,可以在我的博客文章中输入评论但是当评论显示在网页上时,我添加到div的背景颜色要么大或要小。我已经提供了以下代码。任何帮助表示赞赏!

    <h2 id="comments-title">Comments</h2>
 <div id="comment-list">
    <?php

}
$commenttimestamp = strtotime("now");

$sql = "SELECT * FROM php_blog_comments WHERE entry='$id' ORDER BY timestamp";
$result = mysql_query ($sql) or print ("Can't select comments from table php_blog_comments.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
    $timestamp = date("l F d Y", $row['timestamp']);
      printf("<div class='comment-ind'><p id='comments'><a id='username' href=\"%s\">%s</a> %s</p>", stripslashes($row['url']), stripslashes($row['name']), $timestamp);
    print("<p class='comments'>" . stripslashes($row['comment']) . "</p><div class='clr'><br></div></div>");

  }
?>

<form id="commentform" method="post" action="process.php">

<p><input type="hidden" name="entry" id="entry" value="<?php echo $id; ?>" />

<input type="hidden" name="timestamp" id="timestamp" value="<?php echo $commenttimestamp; ?>">

<input type="text" name="name" id="name" title="Name (required)" /><br />

<input type="text" name="email" id="email" title="Mail (will not be published) (required)" /><br />

<input type="text" name="url" id="url" title="Website" value="http://" /><br />

<br />
<textarea  title="Your Comment Goes Here" name="comment" id="comment"></textarea></p>

<p><input type="submit" name="submit_comment" id="submit_comment" value="Add Comment" /></p>

</form>
</div>

CSS:

    #comments-title {
    background-color: #282828;
    width: 567px;
    height: 30px;
    font-size: 25px;
    font-family: arial;
    color: #ffffff;
    padding: 5px;
    padding-top: 6px;
    padding-bottom: 4px;
}


#comment-list{
    border:1px solid #dadada;
    width: 565px;
    padding: 5px;
    font-family: Helvetica;
    font-size: 18px;
}

#comments {
    width: 480px;
    font-size: 12px;
    color: #444444;
}

.comments {
    width: 480px;
    height: 20px;
}
.comment-ind {
    background-color: #eeeeee;
    width: 548px;
    position: relative;
    min-height: 10px;
    margin: 5px;
    padding: 8px;
}

图像: alt text http://i37.tinypic.com/28qs7s.png

2 个答案:

答案 0 :(得分:1)

您的问题出在height: 20px;。您可以将其更改为min-height: 20px;,然后它将至少达到该高度,但无论内容如何,​​它都将是20px高。

答案 1 :(得分:0)

我们是否看到适用于此div的整个css。看一下屏幕截图,我猜想文本段落左侧浮动,包含div不包裹。尝试删除高度并将overflow:hidden添加到包含.comments div。这样,高度将根据包含的大小进行调整。