简体   繁体   中英

div height is not growing according to content size

Hi I have a dynamic content $search_results and I am trying to display It inside a <div> . but the problem is the the height of the <div> is not increasing according to the content size. $search_results is a tabled content like <table><tr><td>Values</td></tr></table>

and here is the code.

<div  style="background:#CCC;">
<div style="height:500px;width:1000px;margin:auto;padding-top:20px;">
<div style="width:200px;float:left; background:#666;color:white;">
<form name="SearchForm" action="" method="post">
<ul class="SearchList">
<li class="firstlist">Search</li>

<li>
   <input  type="text"  class="text_medium" value="Keywords" name="KeywordsTextBox" onblur="if(this.value=='') this.value='Keywords'" onFocus="if(this.value =='Keywords' ) this.value=''" >
</li>

<li>
  <select name="SearchValues" class="select_medium">
     <option value="Search1">Search option 1</option>
     <option value="Search1">Search option 2</option>
     <option value="Search1">Search option 3</option>
     <option value="Search1">Search option 4</option>
  </select>
</li>

  <input type='submit' name='SearchButton' class='Small_Button'  value='Search'>
</li>

</ul>
</form>
</div>
<div style="width:800px;float:right; background:#C69;">
<form name="ResultForm" method="post" action="">
<?php 

//$serachObj =  new Search()

//$search_results = $serachObj->search();

echo $search_results; 
?>
</form>
</div>
</div>
</div>

I have tried style="min-height:500px;" but its not working. Any suggestions ?.

There is float in your the child DIV's . So, you have to clear the it's parent. Define overflow:hidden to the parent DIV. For example write like this:

<div style="overflow:hidden;min-height:500;width:1000px;margin:auto;padding-top:20px;">
 <div style="float:left"></div>
 <div style="float:left"></div>
</div>

UPDATED

<div style="min-height:500;width:1000px;margin:auto;padding-top:20px;">
     <div style="float:left"></div>
     <div style="float:left"></div>
     <div style="clear:both"></div>
</div>

Add overflow:auto to the parent div

DEMO

将div高度设为自动。

height:auto;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM