首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何改变纯css动画的前面颜色?

如何改变纯css动画的前面颜色?
EN

Stack Overflow用户
提问于 2019-12-31 00:04:23
回答 3查看 65关注 0票数 0

在下面的纯CSS加载中,前面的颜色是白色的,所以它不会在白色屏幕上显示任何内容。如何改变前面的颜色?

代码语言:javascript
复制
.lds-hourglass {
  display: inline-block;
  position: relative;
  width: 120px;
  height: 120px;
  background-color: black;
}

.lds-hourglass:after {
  content: " ";
  display: block;
  border-radius: 50%;
  width: 0;
  height: 0;
  margin: 8px;
  box-sizing: border-box;
  border: 32px solid #fff;
  border-color: #fff transparent #fff transparent;
  animation: lds-hourglass 1.2s infinite;
}

@keyframes lds-hourglass {
  0% {
    transform: rotate(0);
    animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
  }
  50% {
    transform: rotate(900deg);
    animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  }
  100% {
    transform: rotate(1800deg);
  }
}
代码语言:javascript
复制
<div class="lds-hourglass">Loading....</div>

EN

回答 3

Stack Overflow用户

发布于 2019-12-31 00:08:54

只需将背景色设置为:before即可。

请参阅代码片段:

代码语言:javascript
复制
.lds-hourglass {
    display: inline-block;
    position: relative;
    width: 120px;
    height: 120px;

}

    .lds-hourglass:after {
        content: " ";
        background-color:black;
        display: block;
        border-radius: 50%;
        width: 0;
        height: 0;
        margin: 8px;
        box-sizing: border-box;
        border: 32px solid #fff;
        border-color: #fff transparent #fff transparent;
        animation: lds-hourglass 1.2s infinite;
    }

@keyframes lds-hourglass {
    0% {
        transform: rotate(0);
        animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
    }

    50% {
        transform: rotate(900deg);
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    }

    100% {
        transform: rotate(1800deg);
    }
}
代码语言:javascript
复制
<div class="lds-hourglass">
Loading....
</div>

票数 1
EN

Stack Overflow用户

发布于 2019-12-31 00:10:11

此动画使用borders生成此形状,更改这些值以更改颜色:

透明边框: 32px solid #f00;

  • border-color:#f00 transparent #f00 transparent;

要更改文本的loading..颜色,只需将此行color: #fff添加到您的lds-hourglass样式。

代码语言:javascript
复制
.lds-hourglass {
    display: inline-block;
    position: relative;
    width: 120px;
    height: 120px;
    background-color: #fff;
    color: #f00;
}

    .lds-hourglass:after {
        content: " ";
        display: block;
        border-radius: 50%;
        width: 0;
        height: 0;
        margin: 8px;
        box-sizing: border-box;
        border: 32px solid #f00;
        border-color: #f00 transparent #f00 transparent;
        animation: lds-hourglass 1.2s infinite;
    }

@keyframes lds-hourglass {
    0% {
        transform: rotate(0);
        animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
    }

    50% {
        transform: rotate(900deg);
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    }

    100% {
        transform: rotate(1800deg);
    }
}
代码语言:javascript
复制
<div class="lds-hourglass">Loading....</div>

票数 1
EN

Stack Overflow用户

发布于 2019-12-31 00:12:51

尝试用border-color: #fff black #fff black;替换border-color: #fff transparent #fff transparent;

代码语言:javascript
复制
.lds-hourglass {
    display: inline-block;
    position: relative;
    width: 120px;
    height: 120px;
    background-color: white;
}

    .lds-hourglass:after {
        content: " ";
        display: block;
        border-radius: 50%;
        width: 0;
        height: 0;
        margin: 8px;
        box-sizing: border-box;
        border: 32px solid #fff;
        border-color: #fff black #fff black;
        animation: lds-hourglass 1.2s infinite;
    }

@keyframes lds-hourglass {
    0% {
        transform: rotate(0);
        animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
    }

    50% {
        transform: rotate(900deg);
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    }

    100% {
        transform: rotate(1800deg);
    }
}
代码语言:javascript
复制
<div class="lds-hourglass">Loading....</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59533625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档