Your element shrinks to zero, then disappear. But you have added either padding or margin to the element, which doesn’t count for it’s height. So when it’s zero, it’s still the height of the margin or padding, then it hides. So there’s your glitch.
So, good practice : when you do reveal/hide interaction, add a special container to do that and don’t put any styling on it. Apply your margins and paddings to the elements inside it.
So add an extra div around all your things, and target it for the interaction instead of the one that has pad/marg.