Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic height for DIV

Tags:

I have the following DIV

<div id="products">  </div>  #products {     height: 102px; width: 84%;     padding:5px; margin-bottom:8px;     border: 1px solid #EFEFEF; } 

Now inside the DIV, I am dynamically generating 4 links. But sometimes there could be more or less than 4 links. How can I change the CSS to dynamically resize the DIV according to its contents?

like image 768
Refti Avatar asked Nov 02 '10 06:11

Refti


2 Answers

set height: auto; If you want to have minimum height to x then you can write

height:auto; min-height:30px; height:auto !important;        /* for IE as it does not support min-height */ height:30px;                   /* for IE as it does not support min-height */ 
like image 165
Chinmayee G Avatar answered Oct 09 '22 10:10

Chinmayee G


calculate the height of each link no do this

document.getElementById("products").style.height= height_of_each_link* no_of_link 
like image 29
Praveen Prasad Avatar answered Oct 09 '22 11:10

Praveen Prasad