CSS 动画动画在后续元素上有延迟

CSS animation animation with delay on subsequent elements

我正在尝试以交错方式将三个点 "falling" 动画化到屏幕上:每个点出现在视口中时都有轻微的延迟。出于某种原因,延迟没有应用于后续元素,它们都立即出现。标记:

  <div class="ellipsis">
    <span>&#x2B24;</span>
    <span>&#x2B24;</span>
    <span>&#x2B24;</span>
  </div>

CSS(由 postcss 提供嵌套):

.ellipsis {
  padding: 0;
  margin: 0.33rem 0;
  width: 1rem;
  letter-spacing: 0.23rem;
  animation: fall 1.3s forwards;

  & span {
    display: inline-block;
    font-size: var(--step-0);
  }

  & :nth-child(2) {
    animation-delay: -0.4s;
  }

  & :nth-child(3) {
    animation-delay: -0.7s;
  }
}

@keyframes fall {
  0% {
    transform: translateY(-44px);
  }

  100% {
    transform: translateY(7px);
  }
}

我忘记了什么?

要为点设置动画,而不是 容器 ,您应该将 animation: fall 1.3s forwards; 添加到 span,而不是至 .ellipsis.

动画应该在 <span> 元素而不是 .ellipsis 容器上:

.ellipsis {
  padding: 0;
  margin: 0.33rem 0;
  width: 1rem;
  letter-spacing: 0.23rem;
}

.ellipsis span {
  display: inline-block;
  animation: fall 1.3s forwards;
  transform: translateY(-78px);
  font-size: var(--step-0);
}

.ellipsis span:nth-child(2) {
  animation-delay: 0.7s;
}

.ellipsis span:nth-child(3) {
  animation-delay: 1.4s;
}

@keyframes fall {
  0% {
    transform: translateY(-78px);
  }

  100% {
    transform: translateY(7px);
  }
}
<div class="ellipsis">
  <span>&#x2B24;</span>
  <span>&#x2B24;</span>
  <span>&#x2B24;</span>
</div>