我试图通过使用 javscript 将一个元素的高度设置为另一个元素的高度,我尝试使用 jquery height() 方法但它不起作用,因为其中一个元素的高度设置为自动:
#content
{
background-color:#F2F2F2;
width:1000px;
margin:0px auto;
text-align:left;
min-height:900px;
height:auto;
border-top:5px solid #032F76;
border-bottom:5px solid #032F76;
overflow:auto;
}
那么有什么简单的方法可以获取高度设置为自动的元素的高度吗?
最佳答案
jQuery 的 .height() 方法仍然 返回数字高度值,即使它设置为自动。但请务必考虑边距、填充和边框。
我对您的 CSS 进行了测试,以确保 .height() 工作正常。
http://jsfiddle.net/ysMge/8/
jQuery 有 3 个高度计算函数,它们以不同方式考虑边距、填充和边框值。
请检查:
$("#content").height()
$("#content").outerHeight()
$("#content").innerHeight()
http://api.jquery.com/height/
http://api.jquery.com/outerHeight/
http://api.jquery.com/innerHeight/
关于javascript - 如何获得高度为 :auto? 的元素的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9448688/