Firefox and Chrome seem to render box-shadow quite differently

后端 未结 5 726
青春惊慌失措
青春惊慌失措 2021-01-17 11:00

I was testing a box-shadow effect in both Chrome and Firefox and I was surprised to see a drastic difference in rendering between the two browsers. Notably, Firefox\'s rende

5条回答
  •  既然无缘
    2021-01-17 11:40

    This is a long standing bug in Chrome which is fixed for Chrome 73 (coming March 2019).

    https://www.chromestatus.com/feature/6569666117894144

    Historically, Blink's blur-radius interpretation has been at odds with both the CSS and Canvas2D specs: Blink shadows cover about half the expected area (see linked bug). With this change Gaussian blur sigma is now computed as 1/2 blur-radius, as mandated by spec. Blink's shadow implementation now matches FireFox and Safari.

    Note: This bug is older than forking Blink from WebKit. Safari ever had a different graphics engine.

    https://bugs.chromium.org/p/chromium/issues/detail?id=179006

    So the exact formula to preserve appearance through this change is
    R' = 2 * (0.288675 * R + 0.5)

    R' (new)     R (previously)
    Chrome 73+   Chrome 72 and below
    1.5px        1px
    2px          2px
    3px          3px
    3px          4px
    4px          5px
    4.5px        6px
    
    R' ≈ 0.7 * R       for R = 7px ... 12px
    R' ≈ 0.6 * R       for R = 22px ... ∞
    

提交回复
热议问题