我有一个小问题…
我创建了一个div,通常情况下,它会扩展到适合内容的高度,但是…现在我有问题了。
我的内容是从Sql语句返回的,它没有扩展到适合它的高度,一个工作的非动态版本是
#commentblock {
min-height:50px;
width:90%;
margin:20px auto;
padding:10px;
border:1px solid #999;
}
我的代码如下(它在for循环中为每个实例创建一个新的div)
// Now lets query to grab the responses to this fault
$querytwo = "SELECT * FROM comments WHERE faultid=".$fid;
// execute query
$resulttwo = mysql_query($querytwo) or die ("Error in query: $querytwo. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($resulttwo) > 0) {
// print them one after another
while($row = mysql_fetch_row($resulttwo)) {
// lets make this render then
echo "<div id='commentblock'>";
echo "<div class='loggedby'>Logged By : <span>".$row[4]."</span><p class='contactno'>Entered : <span>".$row[3]."</span></p></div>";
echo "<div class='info'><span>".$row[2]."</span></div>";
echo "</div>";
}
}
// free result set memory
mysql_free_result($resulttwo);
// close connection
mysql_close($connection);
提前感谢:)
明白了,内容在一个继承了浮动属性的span中。移除浮动-现在一切正常:)
可能与动态代码无关,而是无效的HTML。
你正在使用:
id='commentblock'
…在一个循环中,在同一个页面上创建多个相同的id,这是无效的。
你应该改成:
class='commentblock'
和引用你的CSS为:
.commentblock
…而不是:
#commentblock