HTML中的style.width和offsetwidth之间的区别? [英] Difference between style.width and offsetwidth in HTML?

查看:91
本文介绍了HTML中的style.width和offsetwidth之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到 offsetwidth 是一个稍大的数字。同样,对于 style.height offsetheight

通常,元素的offsetWidth是一个度量,它包含元素边框,元素水平填充,元素垂直滚动条(如果呈现,如果呈现)和元素CSS宽度。


来源: https://developer.mozilla.org/zh/DOM/element.offsetWidth






所以,它是包含边框和填充的元素的宽度。高度相同的东西。


I notice that offsetwidth is a slightly bigger number. Similarly for style.height and offsetheight.

解决方案

Typically, an element's offsetWidth is a measurement which includes the element borders, the element horizontal padding, the element vertical scrollbar (if present, if rendered) and the element CSS width.

Source: https://developer.mozilla.org/en/DOM/element.offsetWidth


So, it's the width of your element with border and padding included. Same thing for height.

这篇关于HTML中的style.width和offsetwidth之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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