您可以在动画开始时将正方形居中,margin-left:-3.5vh;
并在关键帧动画中将其设置为 0:
演示
CSS:
#outer{
background: orange;
height: 7vh;
width: 100%;
}
#logo{
height: 7vh;
position: absolute;
left: 50%;
margin-left:-3.5vh;
width: 7vh;
-webkit-animation: moveLeft 1s forwards ease-in-out;
-moz-animation: moveLeft 1s forwards ease-in-out;
-ms-animation: moveLeft 1s forwards ease-in-out;
-o-animation: moveLeft 1s forwards ease-in-out;
animation: moveLeft 1s forwards ease-in-out;
background: black;
}
@-webkit-keyframes moveLeft {
from {left: 50%;margin-left:-3.5vh;}
to {left: 0;margin-left:0; -webkit-transform: rotate(360deg);}
}
@-o-keyframes moveLeft {
from {left: 50%;margin-left:-3.5vh;}
to {left: 0;margin-left:0; -webkit-transform: rotate(360deg);}
}
@-moz-keyframes moveLeft {
from {left: 50%;margin-left:-3.5vh;}
to {left: 0;margin-left:0; -webkit-transform: rotate(360deg);}
}
@keyframes moveLeft {
from {left: 50%;margin-left:-3.5vh;}
to {left: 0;margin-left:0; -webkit-transform: rotate(360deg);}
}