【发布时间】:2020-07-30 23:52:59
【问题描述】:
我有一个星号图标的最小 SVG 图像:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<defs>
<style>
.a {
fill: red;
transform-box: fill-box;
transform-origin: center;
}
</style>
</defs>
<!-- x = 45 because it's 10px wide and centered around x=50, so x0 == 45, x1 == 55 -->
<rect class="a" x="45" y="0" width="10" height="100"/>
<rect class="a" x="45" y="0" width="10" height="100" transform="rotate(-45)"/>
<rect class="a" x="45" y="0" width="10" height="100" transform="rotate( 45)"/>
<rect class="a" x="45" y="0" width="10" height="100" transform="rotate(-90)"/>
</svg>
这在 Firefox 75 和 Chrome 80 中可以正确呈现,但在 iOS 或 macOS 上的 Safari 则不正确:
火狐75:
铬 80:
iOS 13 上的 Safari
但在 Safari 上,transform-origin 似乎被忽略了,或者与每个 <rect> 元素上的 transform="" 属性相比,应用乱序:
我听说它会在 macOS Safari 上呈现相同的损坏图像(我现在无法立即访问 macOS Safari,所以我无法从那里发布屏幕截图,抱歉)。
我在 Google 上搜索过 Safari/WebKit 是否缺乏对 transform-box、transform-origin 或 transform="rotate(deg)" 的支持,但据我所知,它们多年来都得到 Safari 的完全支持 - 所以我不明白为什么它会乱序应用转换并导致渲染中断。
【问题讨论】:
-
大概 safari 不支持 SVG 上的 transform-origin 或 transform-box。
-
@RobertLongson 但是 MDN 和 CanIUse.com 都报告说 Safari 支持 SVG 的
transform-origin和transform-box,没有关于行为差异的注释或其他说明。 -
可能文档有误。
-
@RobertLongson 看起来文档只是在技术上是正确的 - 看起来 Safari 确实支持 SVG 中的
transform-originCSS 属性,但它不将它用于transform=""链,这很奇怪(并且与所有其他浏览器相反......) -
@RobertLongson 我正在向 MDN 的浏览器兼容性数据库提交 PR 以改进文档。
标签: svg safari webkit chromium