tags:

views:

130

answers:

3

I set a div to height:100px; width:50px, but when the content of the div is changing dynamically, I want to let the height adapt to the change.

What should I do?

+6  A: 

Easiest way is to do

min-height: 100px;

this will set the minimum height of the div to 100px but allow it to grow as the content grows.

Jeremy B.
Also, in IE6, the height property acts like min-height (where the container's height scales with the content, instead of letting it spill out over-top of other elements). If you specify an overflow property other than visible, then it will function properly.
Adrian
+1  A: 

min-height is a good practice. Also, rather than expressing the height in "px," use "em" which will scale with the current font.

BJ Safdie
+1  A: 

Like others have said min-height and min-width is what you need. It's a css rule and applied like this:

#someDivName {

min-height: 100px;
min-width: 50px;

}

Now your div will be 100px by 50px but if the content inside is bigger, it will adapt to the change. Like others before me have mentioned, min properties do not work in IE6 but who cares about IE6 anymore anyway. Even major sites like youtube has discontinued support for it.

Cameroon
yeah!who cares?! :)
T_t