I'm trying to make a loading spiner with icon from https://materialdesignicons.com/ but the icon doesn't just rotate, it also moves slightly from the center.
I have these styles:
@keyframes spin-animation {
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.spin:before {
display: block;
transform-origin: center center;
-webkit-backface-visibility: hidden;
-webkit-animation: spin-animation 2s linear infinite;
animation: spin-animation 2s linear infinite;
}
It's <i class="mdi mdi-something spin">
element. So it has added :before
with content of the icon.
This element sits in an absolutely positioned wrapper, with display: flex
, horizontally and vertically centered.
The problem is that when the icon rotates, it doesn't rotate around its center. The axis moves by a little. The icon doesn't stay in one centered position, instead it moves slightly.
I've tried:
- Giving width and height to the
i
element - Giving width and height to the
:before
element - Moving the
spiner
animation fromi
to:before
- Different styles which I've found on stackoverflow, e.g.
transform-origin: center center;
The icon itself has the same x
and y dimensions
so it shouldn't be a problem. The dimensions change when it rotates, but I guess that's correct?