【发布时间】:2019-09-14 01:32:03
【问题描述】:
我有不同background-colors 的元素。单击链接时,我想用不同的颜色(黄色)突出显示元素,然后淡化回元素的原始颜色。我知道元素的color 有currentColor,但background-color 没有类似的东西。
如何从高亮颜色平滑过渡回元素的原始background-color? 现在它从高亮颜色淡化为透明,然后在动画时突然跳回原始颜色结束。
:target td {
animation: highlight 1s;
}
@keyframes highlight {
from {
background-color: yellow;
}
to {
/* How do I set this back to the element's original background-color? */
background-color: transparent;
}
}
<ul>
<li>
<a href="#link1">Link #1</a>
</li>
<li>
<a href="#link2">Link #2</a>
</li>
<li>
<a href="#link3">Link #3</a>
</li>
</ul>
<table>
<tr id="link1">
<td>This is Link #1</td><td>// Fine.</td>
</tr>
<tr id="link2">
<td bgcolor="orange">This is Link #2</td><td>// Ugly.</td>
</tr>
<tr id="link3">
<td bgcolor="red">This is Link #3</td><td>// Ugly.</td>
</tr>
</table>
【问题讨论】:
-
如果曾经有一段时间“只使用 jQuery”是有效的...... :)
-
但是,哦!使用零外部库的乐趣!
标签: css css-transitions css-animations background-color