开发者

Can a div with a specified height (in CSS) automatically scale?

开发者 https://www.devze.com 2022-12-27 11:10 出处:网络
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.

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开发者_Go百科 I do?


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消