【发布时间】:2019-01-06 09:01:23
【问题描述】:
我试图获取一个元素的宽度,但是返回的值是错误的
let container = document.querySelector('.content')
console.log(container.offsetWidth) //this will log wrong value 1182px instead of 960px
console.log(getComputedStyle(container).width) //1182px anyway I don't have any idea from where the value comes
我不知道为什么返回的值是错误的
【问题讨论】:
-
不,虽然使用计算的结果相同
-
见this answer。应该使用
box-sizing: border-box。
标签: javascript containers width