html - Flash CSS 颜色在先前颜色和新颜色之间

标签 html css less

假设我有一个 div,其中添加了 background-color:red or green 的颜色。我想让这个闪光变成另一种颜色,其中“非闪光”是以前的颜色值。

HTML
<div class='red make-green flash'></div>

LESS
.red{
  background-color:red;
  .make-green{
    background-color:green;
  }
}
.flash{
   animation: flash 2s infinite;
}
@keyframes flash {
 0%{
    background-color:blue;
 }
 50%{
    background-color:            ;<-- what goes here?
 }
 100%{
    background-color:blue;
 }
}

如果我们删除 .make-greendiv 应该闪烁 red |蓝色,使用make-green它会闪烁绿色|蓝色

最佳答案

如果您同意non-perfect browser support,您可以使用css变量。 .

:root {
  --bg: red;
}

.red {
  height: 100px;
  width: 100px;
  background-color: var(--bg);
}

.make-green {
  --bg: green;
}

.flash {
  animation: color 2s infinite;
}

@keyframes color {
  0% {
    background-color: blue;
  }
  50% {
    background-color: var(--bg);
  }
  100% {
    background-color: blue;
  }
}
<div class='red make-green flash'></div>
<div class='red flash'></div>

关于html - Flash CSS 颜色在先前颜色和新颜色之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55380983/

相关文章:

javascript - 添加tooltip,其值与span值相同

html - 当文本输入获得焦点时,将光标移动到底部

css - Nightwatch 无法找到/单击下拉选项

javascript - 仅来自类的样式属性

colors - LESS 颜色函数 lighten 和 tint 之间有什么区别?

php - 向 php html 电子邮件添加样式

css - 如何将 DIV 置于 FRAMESET 之上?

css - 我可以使用 font-family :Helvetica Neue Light 获得与 photoshop 中相同的效果吗

html - 用 less/css 覆盖字体很棒的图标

css - 使用 Less/CSS 同时为所有选择器设置样式链接(<a> 标签)?