<分区>
<分区>
这可能是个愚蠢的问题,但我想知道如何让我的代码中的标签将颜色从紫色渐变变为红色,然后再自行变回原来的颜色,而无需将鼠标悬停在标签或其他任何东西上。
我一直在尝试做一些研究,并且不断遇到称为 webkit 和 webkit 动画的东西。
我不确定如何使用它,因为我是 html、css 和 js 的初学者。有人可以为我提供一个示例,说明如何完成我正在寻找的颜色之间的过渡吗?
最佳答案
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
-webkit-animation-name: example; /* Safari 4.0 - 8.0 */
-webkit-animation-duration: 4s; /* Safari 4.0 - 8.0 */
animation-name: example;
animation-duration: 4s;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
/* Standard syntax */
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
<p><b>Note:</b> When an animation is finished, it changes back to its original style.</p>
</body>
</html>
关于html - 如何让文本在CSS中改变颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40552735/