Problem is that you are using transform: translate(-50% , -50%);
to center your element but in your @keyframes
you override transform
by rotation()
which overrides your translate()
. If you would put translate()
to animation too your div would be rotating around because origin
(the anchor of rotation) would be different each frame.
So you can:
1) Center your element with left
and top
like this:
div {
position: absolute;
top: calc(50% - 50px);
left: calc(50% - 50px);
width: 100px;
height: 100px;
border: 16px solid rgb(235, 235, 235);
border-top: 16px solid rgb(83, 83, 192);
border-radius: 50%;
animation: loading 2s linear infinite;
/*transform: translate(-50% , -50%);*/
}
@keyframes loading {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
<div></div>
2) or use some parent element which will be centered and your animated div will be inside of it.
.child {
width: 100px;
height: 100px;
border: 16px solid rgb(235, 235, 235);
border-top: 16px solid rgb(83, 83, 192);
border-radius: 50%;
animation: loading 2s linear infinite;
}
.parent {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50% , -50%);
}
@keyframes loading {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
<div class="parent">
<div class="child"></div>
</div>
+ I've deleted transition-property
because you don't need it. You are using animation
not transition
.