CSS animation trick

WangYeUX
Sep 1, 2023

When attempting to implement a collapsible component with CSS animation, I encountered an issue where the content underneath the collapse component appeared to overlap. This problem arose due to the default ‘overflow’ property being set to ‘visible.’ This setting means that during the collapse animation, the height of the content container decreases, but the content itself remains visible outside of the container.

When overflow is set to visible(default), the content overlaps

To resolve this issue, you can simply apply the ‘overflow: hidden’ CSS property to the collapse content. This adjustment ensures that the content within the collapse container remains hidden as it contracts, preventing any unwanted overlap with other elements.

When overflow is set to hidden, it works well

--

--

WangYeUX

A front-end developer who likes designing stuffs. Technical blog rookie. Loving sharing.