【问题标题】:css - center loading animationcss - 中心加载动画
【发布时间】: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); }
}

动画看起来像预期的那样,但是元素没有居中。当“动画”属性被移除时,元素被正确定位。如何将加载动画定位到按钮的中心?

https://jsfiddle.net/f9993ttm/

【问题讨论】:

标签: css animation centering


【解决方案1】:

您的动画正在覆盖您的转换属性。

试试类似的东西:

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg) }
    100% { transform: translate(-50%, -50%) rotate(360deg)  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-11
    • 1970-01-01
    • 2016-05-24
    相关资源
    最近更新 更多