Chrome SVG夹式路径在监视器上行为不足
下面我有一个小的 HTML 片段,
<p style="clip-path: polygon(0 0, 100px 0, 100px 10px, 0 10px)">Lorem ipsum dolor sit amet</p>
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100">
<text y=16 clip-path="polygon(0 0, 100px 0, 100px 10px, 0 10px)">Lorem ipsum dolor sit amet</text>
</svg>
我预计 svg
会像 p
一样被剪裁。像下面这样,
但是将其移动到我的另一台显示器(以 125% 缩放比例运行)时,它会发生变化,
然后我尝试使用 Macbook,运行速度为 200%缩放后,剪辑就消失了
So I have a small HTML snippet below,
<p style="clip-path: polygon(0 0, 100px 0, 100px 10px, 0 10px)">Lorem ipsum dolor sit amet</p>
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100">
<text y=16 clip-path="polygon(0 0, 100px 0, 100px 10px, 0 10px)">Lorem ipsum dolor sit amet</text>
</svg>
I expected the svg
to be clipped as p
does. Something like this below,
But moving this to my other monitor, which runs at 125% scaling, it changes,
Then I tried with the Macbook, which runs at 200% scaling, and the clip is gone ????.
I found the alternative solution, which is by using Window.devicePixelRatio
to correctly scale the clip-path
(because the SVG is generated on the fly).
The problem is that this only happens on Chrome (and other Chromium-based). While on Firefox it's consistent across all monitors. So which browser is the correct behavior? Is this bug for Chrome? I can't find any existing questions about this on StackOverflow. ????
Thanks,
edit: oh yeah I just found it's been on bug tracker since 2018 https://bugs.chromium.org/p/chromium/issues/detail?id=800784
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将
clip-path
应用到 SVG,而不是
,它的行为将符合您的预期。If you apply the
clip-path
to the SVG, rather than the<text>
, it behaves as your expect.