html - 如何让文本在CSS中改变颜色?

标签 html css colors webkit

<分区>

这可能是个愚蠢的问题,但我想知道如何让我的代码中的标签将颜色从紫色渐变变为红色,然后再自行变回原来的颜色,而无需将鼠标悬停在标签或其他任何东西上。

我一直在尝试做一些研究,并且不断遇到称为 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/

上一篇:javascript - 要求用户从调色板中选择一种颜色并通过 JavaScript 修改 SVG

下一篇:javascript - 随着背景颜色的变化更改按钮颜色?

相关文章:

php - 十六进制网页颜色

r - 如何在 R persp 函数中沿 z 轴定位配色方案?

javascript - Material-UI样式: convert functional component to class component

ipad - 如何在 iPad 上设置 NSAttributedString 的颜色?

javascript - 删除输入字段值 onclick

html - 在 CSS 中隐藏和取消隐藏 div 时遇到问题

php - 让网站输入一个随机数

html - HTML5 和 CSS3 中类似杂志的水平滚动

javascript - 如何在 HTML 中搜索表格中的数据

javascript - CSS 缩放打破 Microsoft Edge 中的 caretRangeFromPoint