简体   繁体   English

动态设置div的高度

[英]Dynamically setting height of a div

I have a div called list which is getting its content from database. 我有一个名为list的div,它正在从数据库中获取其内容。 I have set the vertical scroller such that whenever its height exceeds 100px,it will use scroll bar. 我已经设置了垂直滚动条,以便每当其高度超过100px时,它将使用滚动条。

Now my problem is when the content of the list gets empty or less than 100px,it is setting to same height of 100px .I want the height of div dynamically as per the content of it and at the same time use vertical scroll bar whenever its height crosses 100px. 现在我的问题是当列表的内容为空或小于100px时,将其设置为100px的高度。我要根据其内容动态调整div的高度,同时只要它的内容使用垂直滚动条高度超过100像素。

#list {
height: 100px;
width: 1100px;
overflow-x: hidden;
overflow-y: auto;
}

Any help will be highly apreciated 任何帮助都将受到高度重视

Use max-height:100px instead of height:100px . 使用max-height:100px而不是height:100px

You can see the difference here: jsFiddle example . 您可以在这里看到区别: jsFiddle示例 Chop the text down to see the div shrink. 切下文字以查看div缩小。

height:auto;
max-height:100px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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