css - 让球改变颜色
问题描述
这是一个相对简单的问题,但我似乎看不出我在这里做错了什么。我只想让球在 0%、%50 和 %100 标记处从红色变为蓝色,再变为黄色。目前我没有看到任何变化。
谢谢你的帮助,
安娜
#ball {
background-color: red;
height: 50px;
width:50px;
border-radius: 50%;
animation-name: ball;
animation-duration: 4s;
@keyframes ball{
0% {
background-color: red;
}
50% {
background-color: blue;
}
100% {
background-color: yellow;
}
}
}
<html>
<body>
<div id="ball">
</div>
</body>
</html>
解决方案
移出@keyframes
你的球样式(除非你使用像 SASS 这样的 CSS 预处理器......)
#ball {
background-color: red;
height: 50px;
width: 50px;
border-radius: 50%;
animation-name: ball;
animation-duration: 4s;
}
@keyframes ball {
0% {
background-color: red;
}
50% {
background-color: blue;
}
100% {
background-color: yellow;
}
}
<div id="ball"></div>
改用 SCSS 时,您可以:jsFiddle 示例
推荐阅读
- bash - 使用制表符分隔文件中字段的空格分隔参数
- swift - 第三次返回视图时 ARView 崩溃
- python - 如何使用 python 和 scapy sniff() 和 send() 模拟以太网交换机
- c++ - 类似于 mp-units“向下转换工具”的类型的强别名,仅使用 C++14
- html - Bootstrap 5 列堆叠取决于宽度
- c# - 我如何才能在 C# 中只获取异常堆栈跟踪消息的第一行?
- javascript - ReactJS:超出最大部门/私人路线
- javascript - 如何从两个不同的中继连接中删除共享节点?
- android - Lottie for Xamarin Android 无法正常工作其重叠并在 Xamarin.Android 中产生未接受的动画
- powerbi - 如何在 Power BI 中用 3 列展平数据?