如何使用 CSS 动画更改 CSS 动画中的字体颜色

How do I Change font-color in CSS animation using CSS animation

我正在努力做到这一点,因此当我打开页面时,test 将显示为红色,而 testing 将显示为白色。当我想要保留的页面打开时,我正在使用延迟(如果您 运行 您将看到的程序)。

Css

#hero h1 {
  display: block;
  width: fit-content;
  font-size: 3rem;
  position: relative;
  color: transparent;
  animation: text_reveal .5s ease forwards;
  animation-delay: 1s;
}

#hero h1 .slide {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0;
  background-color: crimson;
  animation: text_reveal_box 1s ease;
  animation-delay: .5s;
}


/* KetFrames */

@keyframes text_reveal_box {
  50% {
    width: 100%;
    left: 0;
  }
  100% {
    width: 0;
    left: 100%;
  }
}

@keyframes text_reveal {
  100% {
    color: white;
  }
}

HTML

<section id="hero">
  <div class="hero container">
    <div>
      <h1><span class="red">test</span> testing<span class="slide"></span></h1>
    </div>
  </div>
</section>

你是这个意思吗?查看 /* added CSS */

下的更改

body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: grey;
}

html {
  font-size: 20px;
  font-family: 'Montserrat', sans-serif;
}

#hero h1 {
  display: block;
  width: fit-content;
  font-size: 3rem;
  position: relative;
  color: transparent;
  animation: text_reveal .5s ease forwards;
  animation-delay: 1s;
}

#hero h1 .slide {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0;
  background-color: crimson;
  animation: text_reveal_box 1s ease;
  animation-delay: .5s;
}


/* KetFrames */

@keyframes text_reveal_box {
  50% {
    width: 100%;
    left: 0;
  }
  100% {
    width: 0;
    left: 100%;
  }
}

@keyframes text_reveal {
  100% {
    color: white;
  }
}

/* added CSS */
.red {
  animation: text_reveal_red ease forwards;
  animation-delay: 1s;
  animation-iteration-count: 1;
}

@keyframes text_reveal_red {
  100% {
    color: crimson;
  }
}
<section id="hero">
  <div class="hero container">
    <div>
      <h1><span class="red">test</span> testing<span class="slide"></span></h1>
    </div>
  </div>
</section>