html - CSS关键帧动画重叠

标签 html css

我正在尝试创建一个按颜色顺序亮起的 4x4 table 。共有 5 种颜色,这些颜色在不同的表格列和行中依次亮起。我设法获得一种颜色,但是当我尝试添加另一个关键帧动画时,它会将两个单元格都更改为新颜色吗?任何帮助将非常感激。下面的代码只显示一种颜色。

HTML:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<center><h1>Light Sequence</h1></center>
<table>
<table style="background-color: #5D5D5D;" table align="center"
<tr>
    <td></td>
    <td></td>
    <td></td>
    <td class="d"></td>
</tr>
<tr>
    <td></td>
    <td class="a"></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td class="c"></td>
    <td></td>
    <td class="b"></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td class="e"></td>
    <td></td>
    <td></td>
</tr>
</table>
</body>

</html>

CSS:

td { width:400px; height:200px; border:2px solid #333; }
td.a { background-color:#5D5D5D; }
td.b { background-color:#5D5D5D; }
td.c { background-color:#5D5D5D; }
td.d { background-color:#5D5D5D; }
td.e { background-color:#5D5D5D; }
.a {
height:200px;
width: 400px;
border: 2px solid #333;
-webkit-animation: animate_bg 3s;
animation: animate_bg 3s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;

@keyframes animate_bg {  
0%   {background-color:#5D5D5D;}  
100% {background-color:yellow;}  

@keyframes animate_bg {
0%   {background-color:#5D5D5D;}
100% {background-color:yellow;}

@-webkit-keyframes animate_bg {
0%   {background-color:#5D5D5D;}
100% {background-color:yellow;}

最佳答案

您所要做的就是更改每个单元格的关键帧名称。如果每个关键帧执行不同的操作,则它应该有一个唯一名称。

例如:

CSS:

td { width:400px; height:200px; border:2px solid #333; }
td.a { background-color:#5D5D5D; }
td.b { background-color:#000000; }
td.c { background-color:#ffffff; }
td.d { background-color:#414141; }
td.e { background-color:#383838; }
.a {
height:200px;
width: 400px;
border: 2px solid #333;
-webkit-animation: animate_bg 3s;
animation: animate_bg 3s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}

.b {
height:200px;
width: 400px;
border: 2px solid #333;
-webkit-animation: animate_bg2 3s;
animation: animate_bg2 3s;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
}

@keyframes animate_bg {  
0%   {background-color:#5D5D5D;}  
100% {background-color:yellow;}  
}

@keyframes animate_bg {
0%   {background-color:#5D5D5D;}
100% {background-color:yellow;}
}

@-webkit-keyframes animate_bg {
0%   {background-color:#5D5D5D;}
100% {background-color:yellow;}
}

@keyframes animate_bg2 {  
0%   {background-color:#000000;}  
100% {background-color:red;}  
}

@keyframes animate_bg2 {
0%   {background-color:#000000;}
100% {background-color:red;}
}

@-webkit-keyframes animate_bg2 {
0%   {background-color:#000000;}
100% {background-color:red;}
}

查看编辑 Live .

关于html - CSS关键帧动画重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28282448/

相关文章:

javascript - 如何从 jsfiddle 中删除外部资源?

javascript - Safari 上的字体问题

javascript - 防止html页面浏览缓存

html - 让输入框中的文本从 X 像素开始

javascript - 如何在 Javascript 中一次获取多个按钮的文本?

css - 在 CSS 中创建 flex 的三 Angular 弧

css - 样式表中的 rails 图像(来自供应商)——我是否需要将所有库(巨大的 css 文件)从 img.png 修改为 asset-url(img.png)?

html - IE8 的 Css 问题 - 标题中 2 个 div 之间出现奇怪的空间

javascript - 切换开关 css

jquery - 使用 Jquery 在 Firefox 中动画背景位置 y