Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating a SVG path using CSS3 around its own center

I have a set of SVG path, one of them is as follows:

<path id="GOL" class="st0" d="M37.5,430.5l-12.4-12.4v-13.3h-4.2c-7.2,0-13.9,2.5-18.7,7.5c-4.7,4.9-7.3,11.3-7.3,18.3
    c0,7,2.6,13.5,7.3,18.3c4.8,5,11.4,7.6,18.6,7.6l4.2,0v-13.7L36.7,430.5z M19.7,435.3l-4.9-4.9l4.9-4.9l4.9,4.9L19.7,435.3z
     M2.4,430.5c0-8.4,5.6-15.1,13.1-16.9v3.8L2.4,430.5l13.1,13.1v3.8C8,445.6,2.4,438.9,2.4,00.5z"></path>

I try to make a rotate-animation with the below code:

.stuck #GOL
{
  fill: red;
  transform: rotate(90deg);
}

#GOL
{
  transition-property: all;
  transition-duration: 2s;
}

The problem is that the path rotates around a distance center which is not regular. I want it to rotate around its own center. I have to use CSS3 (so I can't use svg's own rotate() function).

like image 693
Mostafa Talebi Avatar asked Oct 17 '22 20:10

Mostafa Talebi


1 Answers

Have you tried using transform-origin in your CSS?

transform-origin: 50% 50%;

This will start any transform from the middle of the selector.

like image 131
Stewartside Avatar answered Oct 20 '22 09:10

Stewartside