How To Flip SVG Horizontally?

Viewed 3054

I am trying to flip the following SVG horizontally:

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 36.1 25.8" enable-background="new 0 0 36.1 25.8" xml:space="preserve">
    <g>
        <line fill="none" stroke="#FFFFFF" stroke-width="3" stroke-miterlimit="10" x1="0" y1="12.9" x2="34" y2="12.9"></line>
        <polyline fill="none" stroke="#FFFFFF" stroke-width="3" stroke-miterlimit="10" points="22.2,1.1 34,12.9 22.2,24.7   "></polyline>
    </g>
</svg>

I have tried transform="scale(1, -1) translate(0, -100)" among other variations of this, and all it does is delete the vector. I also have a CodePen here: https://codepen.io/bick/pen/eYNQaqX

Thanks!

1 Answers

Scaling in the negative horizontal direction on it's own would move the group outside of it's own viewbox:

transform="scale(-1 1)"

So you need to translate the group back into the negative horizontal direction at the same time.

transform="scale(-1 1) translate(-36.1 0)"

body {
  background: #000;
}
<svg viewBox="0 0 36.1 25.8">
  <g transform="scale(-1 1) translate(-36.1,0)">
    <line fill="none" stroke="#FFFFFF" stroke-width="3" stroke-miterlimit="10" x1="0" y1="12.9" x2="34" y2="12.9"></line>
    <polyline fill="none" stroke="#FFFFFF" stroke-width="3" stroke-miterlimit="10" points="22.2,1.1 34,12.9 22.2,24.7"></polyline>
  </g>
</svg>

This is also possible with CSS using transform-origin.

body {
  background: #000;
}

.arrow {
  transform: scale(-1, 1);
  transform-origin: center;
}
<svg viewBox="0 0 36.1 25.8">
  <g class="arrow">
    <line fill="none" stroke="#FFFFFF" stroke-width="3" stroke-miterlimit="10" x1="0" y1="12.9" x2="34" y2="12.9"></line>
    <polyline fill="none" stroke="#FFFFFF" stroke-width="3" stroke-miterlimit="10" points="22.2,1.1 34,12.9 22.2,24.7"></polyline>
  </g>
</svg>

Related