Chrome issue SVG transform

2020-02-14 06:27发布

I'm trying to position a svg rectangle with transfrom=translate(). When I tested it, I saw that it doesn't work in Chrome but works nice in Firefox.

I also tried in Chrome with -webkit- but doesn't work either.

In the code snippet you can see whats the problem when its open with Chrome.

Does anyone now a workaround for this or am I doing something wrong?

<svg transform="translate(100,0)">
  <rect width="200" height="200" style="fill:blue;;stroke:black" />
</svg>
<br><br>
<svg style="transform:translate(100px,0)">
  <rect width="200" height="200" style="fill:blue;;stroke:black" />
</svg>

https://jsfiddle.net/suf2reee/

1条回答
我命由我不由天
2楼-- · 2020-02-14 06:32

I think this is a SVG 1.1 vs SVG 2 issue. In SVG 1.1, which is the version that browsers generally support, the transform attribute was not valid for the <svg> element. It is allowed in SVG 2.

Firefox have started implementing some SVG 2 features, whereas Chrome is not so far along.

The simplest solution is just to put your transform on the <rect>.

查看更多
登录 后发表回答