CSS 动画之间的延迟

Delay between CSS animations

我正在尝试在 CSS 中打字 2 行。我的问题是这两行是同时写的。我尝试使用 animation-delay 属性 但它无法正常工作。 我怎样才能输入第一行然后输入第二行?

/*-----------------------LINE 1-----------------------*/

.line-1{
font-family: monospace;
position: relative;
top: 30%;
left: 15%;
width: 24em;
margin: 0 auto;
font-size: 250%;
text-align: left;
white-space: nowrap;
overflow: hidden;
transform: translateY(-50%);
}

/* Animation */
.anim-typewriter{
  animation: typewriter 4s steps(44) 1s 1 normal both,
           blinkTextCursor 500ms steps(44) infinite normal;
}
@keyframes typewriter{
  from{width: 0;}
  to{width: 9.5em;}
}
@keyframes blinkTextCursor{
  from{border-right-color: rgba(255,255,255,.75);}
  to{border-right-color: transparent;}
}

/*-----------------------LINE 2-----------------------*/

/* Animation */
.anim-typewriter2{
  animation: typewriter 4s steps(44) 1s 1 normal both,
         blinkTextCursor 500ms steps(44) infinite normal;
         animation-delay: 4s;
 }
 @keyframes typewriter{
   from{width: 0;}
   to{width: 15em;}
 }
 @keyframes blinkTextCursor{
   from{border-right-color: rgba(255,255,255,.75);}
   to{border-right-color: transparent;}
 }
<p class="line-1 anim-typewriter">Hi, I'm Mohanad,</p>
<p class="line-2 anim-typewriter2">I do cool computer stuff.</p>

/*-----------------------LINE 1-----------------------*/

.line-1, .line-2 {
  font-family: monospace;
  position: relative;
  top: 30%;
  left: 15%;
  width: 24em;
  margin: 0 auto;
  font-size: 250%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transform: translateY(-50%);
}

/* Animation */
.anim-typewriter {
  animation: typewriter1 4s steps(44) 1s 1 normal both,
           blinkTextCursor1 500ms steps(44) infinite normal;
}
@keyframes typewriter1 {
  from {
    width: 0;
  }
  
  to{
    width: 9.5em;
  }
}
@keyframes blinkTextCursor1 {
  from {
    border-right-color: rgba(255,255,255,.75);
  }
  
  to {
    border-right-color: transparent;
  }
}

/*-----------------------LINE 2-----------------------*/

/* Animation */
.anim-typewriter2{
  animation: typewriter2 4s steps(44) 1s 1 normal both,
         blinkTextCursor2 500ms steps(44) infinite normal;
         animation-delay: 5s;
 }
 @keyframes typewriter2 {
   from {
    width: 0;
  }
  
  to {
    width: 15em;
  }
 }
 @keyframes blinkTextCursor2 {
   from {
    border-right-color: rgba(255,255,255,.75);
  }
   
  to {
    border-right-color: transparent;
  }
 }
<p class="line-1 anim-typewriter">Hi, I'm Mohanad,</p>
<p class="line-2 anim-typewriter2">I do cool computer stuff.</p>

我想这就是您要找的。我的猜测是您定义了 2 个具有相同名称的动画,因此您覆盖了它们。您还需要指定从 .line-1.line-2

的属性