使用js获取的css长度和宽度

一,offsetWidthoffsetHeight

1.offsetWidthoffsetHeightdom对象和css相关的属性,用于获取dom元素的实际宽高

2.实际宽高=(border+padding+content),等同于使用开发者工具显示的宽高,

3.不同于css文件里的属性widthheight
css属性的widthheight只有两种情况,
一种是border-box,此时widthheight=(padding+content)不包含border,
一种是content-box,此时wihthheight=(content)不包含paddingborder
在这里插入图片描述在这里插入图片描述

二,clientWIdthclientHeight

1.clientWIdthclientHeight用于获取元素的视口宽高。

猜你喜欢

转载自blog.csdn.net/qq_40340943/article/details/112394286