I want to create a transition for an auto height in a flex-box container. I have a user bar with name, points, status and alert.
The alert message sometimes is rendered sometimes is not. It uses a display: none
What I'm trying to achieve is to resize smoothly the height of the flex-box container with a transition when I click on the alert message.
Here is a basic example (not working)
const $user_alert = document.querySelector('user-alert')
$user_alert.onclick = () => {
$user_alert.classList.add('hide')
setTimeout(() => $user_alert.classList.remove('hide'), 1e3)
}
body {
display: flex;
width: 100vw;
height: 100vh;
margin: 0;
background-color: aliceblue;
}
user-bar {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
transition: all 2s ease-in-out;
}
user-alert {
cursor: pointer;
color: red;
}
.hide {
display: none;
}
<user-bar>
<user-name>Albert Einstein</user-name>
<user-points>10000</user-points>
<user-status>on</user-status>
<user-alert>Time to Party Hard</user-alert>
</user-bar>
I cannot figure out how to create a simple transition without defining heights for each element inside the user bar... maybe it's not possible using display: none
.
Any help or idea will be really appreciate!