=> Why Your Animation Is Not Working
You write this:
.box {
display: none;
transition: all 0.3s ease;
}
And expect animationβ¦
π But it disappears instantly.
=> The Real Problem
display: none removes the element from the DOM flow.
That means:
π No rendering
π No animation
π No transition
=> Why Transition Fails
CSS transitions need:
- a starting state
- an ending state
But with display: none:
π Element doesnβt exist visually
So nothing animates.
=> The Correct Way
Use opacity + visibility:
.box {
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
}
.box.active {
opacity: 1;
visibility: visible;
}
Now animation works smoothly.
=> Better Animation with Transform
.box {
opacity: 0;
transform: translateY(10px);
transition: all 0.3s ease;
}
.box.active {
opacity: 1;
transform: translateY(0);
}
=> When to Use display: none
Use it only when:
π You donβt need animation
π You want to completely remove element
=> What Developers Often Miss
Animation is not just about transition.
It depends on how elements exist in layout.
=> Real UI Tip
For modals, dropdowns, tooltips:
π Avoid display: none for animations
=> What Do You Think?
Have you ever tried animating an element and it just disappeared instantly?
Top comments (0)