I want a div to be a specific height until its content needs more space.
我希望div成为特定高度,直到其内容需要更多空间。
let me explain further:
让我进一步解释一下:
<html>
<section>
<div id="container">
<?php while($row =mysql_fetch_array($result)){
echo '<h2>'.$row["title"].'</h2>';
echo $row["body"];
echo $row["user"];}
</div>
</section>
</html>
Now I want the DIV with ID container to have an height of 200px even if it's empty but as more contents are being populated to it, it should now be responsive and increase in size, I don't want to use height:100px because thats still now what I want.
现在我希望ID容器的DIV高度为200px,即使它是空的,但随着更多内容被填充到它,它现在应该响应并增加大小,我不想使用高度:100px因为那是现在仍然是我想要的。
1 个解决方案
#1
3
This is what you want :
这就是你想要的:
min-height:100px;
It will be 100px high by default, even if there's no content, and will expand if needed.
默认情况下它会高出100px,即使没有内容,如果需要也会扩展。
Example CSS
.min { min-height:100px; width:100px; background:#ccc; margin:10px; }
Example HTML
<div class="min"></div>
<div class="min">
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
</div>
#1
3
This is what you want :
这就是你想要的:
min-height:100px;
It will be 100px high by default, even if there's no content, and will expand if needed.
默认情况下它会高出100px,即使没有内容,如果需要也会扩展。
Example CSS
.min { min-height:100px; width:100px; background:#ccc; margin:10px; }
Example HTML
<div class="min"></div>
<div class="min">
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
<p>Lorem ipsum dolor sit amet,</p>
</div>