【发布时间】:2018-06-20 04:48:53
【问题描述】:
我想在按钮中间添加一个旋转动画,如下所示:
.button {
position: absolute;
display: inline-block;
border: 1px solid grey;
padding: 20px;
}
.button::after {
content: "";
position: absolute;
border: 8px solid #ddd;
border-radius: 50%;
border-top: 8px solid #008;
border-bottom: 8px solid #008;
width: 64px;
height: 64px;
animation: spin 2s linear infinite; /* without the animation, everything is positioned perfectly */
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
动画看起来像预期的那样,但是元素没有居中。当“动画”属性被移除时,元素被正确定位。如何将加载动画定位到按钮的中心?
【问题讨论】:
-
考虑通过以下方式调整定位属性:jsfiddle.net/f9993ttm/3