【问题标题】:Why the getComputedStyle.width/Height giving different values in chrome and edge for display:inline?为什么 getComputedStyle.width/Height 在 chrome 和 edge 中为 display:inline 提供不同的值?
【发布时间】:2018-12-28 11:18:47
【问题描述】:

我有默认值设置为“显示”(即“内联”)的自定义元素,当我在 chrome 中执行 getComputedStyle.Height/Width 时,它以像素为单位返回值,但在 Edge/safari 中它返回“自动” '.这是边缘的错误吗?计算值不应该总是以像素为单位吗?

【问题讨论】:

  • 解释一下?不。这可能是官方定义中的一个缺陷,导致模棱两可。不过,您未提出的问题的答案是offsetHeight

标签: javascript css google-chrome microsoft-edge


【解决方案1】:

我与高级 MSFT 开发人员讨论了这个问题。他们告诉我,当您使用“display: inline;”时,MS Edge 浏览器引擎将忽略您为元素专门设置的样式值,并分配默认值,例如 auto。因此,由于这个原因,MS Edge 返回 auto 值而不是像素数。要获取像素数,您可以删除“显示:内联;”。

这是设计使然,不能将其视为错误。

感谢您的理解。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-19
    • 2012-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    相关资源
    最近更新 更多