考虑到内部元素的利润率,如何获得DIV的高度? [英] How to get the height of a DIV considering inner element's margins?
问题描述
请考虑以下标记:
< div id =outerElement>
< div id =innerElementstyle =border:1px solid blue; background-color:#f0f3f5; margin-top:100px>
TESTE
< / div>
< / div>
我想获得 outerElement
。我注意到,如果我从使用javascript
innerElement
删除垂直边距,我可以得到我想要的但我不能改变 outerElement $内的样式c $ c>。
我该如何操作?
我已经在所有浏览器中尝试了height,scrollheight和offsetHeight。 Chrome为我提供了 scrollHeight
的预期值(包括内部元素的边距)。
添加clearfix,使用jquery height()并再次移除clearfix类。 b
$ b
这会奏效。 :)
Consider de following markup:
<div id="outerElement">
<div id="innerElement" style="border: 1px solid blue; background-color: #f0f3f5; margin-top: 100px">
TESTE
</div>
</div>
I want to get the actual final height of outerElement
using javascript. I noticed that if I remove the vertical margins from innerElement
I am able to get what I want but I cannot alter styles from within the outerElement
.
How do I do this?
Obs:
I already tried height, scrollheight and offsetHeight in all browsers. Chrome gives me the expected value (including inner element's margins) for scrollHeight
. All other browsers fail.
Add clearfix, use jquery height() and remove the clearfix class again.
That's gonna work. : )
这篇关于考虑到内部元素的利润率,如何获得DIV的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!