chrome offsetHeight|clientHeight

用js获取元素定位,发现chrome下,忽略了元素offsetHeight。其他浏览器可以根据子元素的样式计算出父级的高度,盒模型。而chrome则不可以、得为其元素设置高度,才能再通过js获取到offsetHeight。

firfox:

chrome:

设置height由于元素<span>为行内元素,还得添加display:block。

chrome:

另外一个点,offsetHeight|clientHeight的区别:

  offsetHeight包含height、padding、scrollBar、border。

  clientHeight包含height、padding。

  http://help.dottoro.com/ljuxqbfx.php

The offsetHeight returns the height of the visible area for an object, in pixels. The value contains the height with the padding, scrollBar, and the border, but does not include the margin.
The clientHeight property is similar to the offsetHeight property, but it returns the height including only the padding.
原文地址:https://www.cnblogs.com/zaric/p/2261348.html