Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG transform="rotate(180)" does not work in Safari 11

For some reason element

<svg width="1000" height="500" transform="rotate(180)">...</svg>

is shown as not rotated in Safari 11.

Chrome 63 renders it properly.

What's the problem?

Thanks!

like image 354
LaBrie Avatar asked Jan 14 '18 10:01

LaBrie


People also ask

How do you rotate a shape in SVG?

The rotate(<a> [<x> <y>]) transform function specifies a rotation by a degrees about a given point. If optional parameters x and y are not supplied, the rotation is about the origin of the current user coordinate system. If optional parameters x and y are supplied, the rotation is about the point (x, y) .

Can I rotate SVG?

You can also rotate the path of the SVG directly via a transform in the itself.

How does SVG rotate work?

When using an SVG transform attribute, the element and its system of coordinates are simply rotated around the point specified by the second and third arguments of the rotate() function, a point whose coordinates we've computed so that it's situated at the 50% 50% point of the element.


2 Answers

In SVG 1.1 <svg> elements did not support transform attributes. In SVG 2 it is proposed that they should.

Chrome and Firefox implement this part of the SVG 2 specification, Safari does not yet do so and IE11 never will.

You can achieve the same result in browsers that do not support this SVG 2 feature either by replacing the <svg> element by a <g> element or by creating an <g> child element on the <svg> element and putting the transform on the <g> element.

like image 124
Robert Longson Avatar answered Sep 21 '22 14:09

Robert Longson


Browsers allow you to use CSS on the SVG-elements, so an easy fix is to use the CSS transform instead.

<!-- ( works on all elements ) -->
<path style="transform:rotate(180deg)" />
like image 30
arc Avatar answered Sep 23 '22 14:09

arc