简体   繁体   English

div内内容的高度

[英]Height of content inside a div

The content of a page is loaded inside a div: 页面的内容在div中加载:

<div id="content">Some content</div>

The div has a fixed height and uses scroll in case of overflow. div具有固定的高度,并在溢出时使用滚动。 I want to adjust the height (make it smaller) of the div onload if the content does not need the fixed height of the div. 如果内容不需要div的固定高度,我想调整div onload的高度(使其更小)。 How can i meassure the height of the content inside the div? 如何测量div中内容的高度?

I tried to work the other way arround. 我试图以另一种方式工作。 No fixed height and after loading of the page meassuring the height of the div and on overflow adjusting the height of the div to a certain max. 没有固定的高度,并且在加载页面之后测量div的高度,并在溢出时将div的高度调整为一定的最大值。 But that gave problems with certain images in the content that have no set height and width. 但这给内容中没有设置高度和宽度的某些图像带来了问题。 The browser gives back a wrong height of the div because the images may not be loaded yet. 浏览器返回了错误的div高度,因为图像可能尚未加载。 Even with $(window).ready(... 即使有$(window).ready(...

Any help is appreciated! 任何帮助表示赞赏!

What about just setting max-height in the CSS? 仅在CSS中设置max-height怎么样?

And for IE6, you could use CSS expressions: 对于IE6,您可以使用CSS表达式:

<!--[if lte ie6]>
<style>
#content {
   height: expression( this.scrollHeight > 499? "500px" : "auto" ); 
}
</style>
<![endif]-->

This is very ugly, but so is IE6... 这非常丑陋,但是IE6也是如此。

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

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