I have successfully implemented an animation using pure CSS that starts on load. However, I am facing an issue with both opacity
and visibility
as the div continues to take up space even when hidden.
Question
Is there a way to make the div disappear completely like display: none
after the animation is completed?
Notes
- I am looking for a pure CSS solution and would like to avoid any hacky fixes.
- While I have come across similar questions, I have not found a satisfactory answer for this specific problem.
- I decided to use
animation
instead oftransition
because it triggers on load.
.message.success {
background: #28a745;
color: #fff;
animation: autohide 2s forwards;
padding: 1rem;
}
@keyframes autohide {
0% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
opacity: 0;
}
}
<div class="message success">
Success!
</div>
This text below is expected to jump up after animation is done.