-1

Now after the animation is an empty div .text. I have to hide the block completely with smooth opacity animation. (such as display:none, but display: none doesn't animate) How do it with keyframes?

.text {
  animation:  opacity-animation .5s forwards;
}

@keyframes opacity-animation {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
<div class="text">text text text text</div>
This fist stroke of text
R.J. Dunnill
  • 1,874
  • 3
  • 9
  • 20
julupo
  • 19
  • 1
  • 5

2 Answers2

0

animation does not work with display.
But you can try something like this:

.text {
    animation: opacity-animation .5s forwards;
}

@keyframes opacity-animation {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
        height: 0;
    }
}
<div class="text">text text text text</div>
This fist stroke of text

Hope it helps!

AdityaSrivast
  • 948
  • 1
  • 8
  • 14
0

Use position: absolute; in animation.

.text {
  animation:  opacity-animation 2s forwards;
}

@keyframes opacity-animation {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    position: absolute;
  }
}
<div class="text">text text text text</div>
This fist stroke of text
Ehsan
  • 12,231
  • 3
  • 23
  • 42