Hello I was trying to reverse an animation of details and summary. I am able to animate when details is open, when i click again didn't animate in reverse. How to make the animation work when I click summary again? Thank you. This is my HTML code and CSS
HTML
<details>
<summary>I am awesome</summary>
<p>Hi there this is an awesome paragraph</p>
</details>
CSS
html {
height: 100vh;
}
body {
height: 100%;
display: grid;
place-content: center;
font-family: 'Montserrat', sans-serif;
}
details {
background: mistyrose;
padding: 4em;
width: 20rem;
}
details:not(open) summary~* {
animation: anim-rev .5s ease-in;
}
details[open] summary~* {
animation: anim .5s ease-in;
}
@keyframes anim {
0% {
opacity: 0;
margin-top: -50px;
}
100% {
opacity: 1;
margin-left: 0;
}
}
@keyframes anim-rev {
0% {
opacity: 1;
margin-left: 0;
}
100% {
opacity: 0;
margin-top: -50px;
}
}