-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
  • 2,049
  • 3
  • 10
  • 21
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
  • 1,028
  • 1
  • 10
  • 16
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,655
  • 3
  • 25
  • 44