Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我有一个带有 div 的表,该表有 2 列,均为 50% 在大多数浏览器中,我可以使用 offsetWidth 来获取文章的宽度。但在 Safari 中,宽度小于或大于应有的宽度。任何帮助将不胜感激。问候理查德
offsetWidth不是跨浏览器的标准化值。它可能包括也可能不包括滚动条宽度。您可能会得到更一致的数字,clientWidth这些数字往往会排除边距、边框和滚动条。
offsetWidth
clientWidth
可能 offsetWidth 的值是在与其他浏览器不同的时间收集的。尝试在 onload 或 ondomready 事件中调用它。
只需设置宽度和高度 - safari 的错误 - 只需接受它。