如何在jQuery中计算div的高度? [英] How to calculate height of div in jQuery?

查看:77
本文介绍了如何在jQuery中计算div的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处于这样的情况下,我必须根据其内容的数量来设置div的高度,但是我不能在其中给出min-height.我知道我们可以通过以下方式计算div的高度:

I am in such a situation that I have to set height of a div depends on the amount of content in it, I can't give min-height in it. I know we can calculate height of div by :


$("#divid").height();

因此,有什么方法可以在不具有div参数的情况下计算div的高度,并根据其内容的多少来赋予div高度.

So is there any way we can calculate height of a div without having height parameter in it and give height to that div depends on the amount of content in it.

我希望我能清楚地解释它.

I hope I explained it clearly.

谢谢

推荐答案

就像您说的那样,对于.height(),不需要为要使用的高度定义实际高度.这是一个显示效果的jsfiddle: http://jsfiddle.net/nWb5j/

Just like you said, with .height(), there does not need to be an actual height defined for that to be used. here is a jsfiddle showing it in action: http://jsfiddle.net/nWb5j/

这篇关于如何在jQuery中计算div的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆