I am attempting to create a CSS animated dropdown/expandable component. At present, I have classes for expanded and collapsed states defined as shown:
.expanded {
margin-top: 0;
}
.collapsed {
margin-top: -100%;
}
However, when I apply these classes based on the dropdown state, it appears that -100%
refers to -100%
of the element's width, rather than its height as intended. This results in the dropdown not collapsing fully when the element's height exceeds its width. Is there a way to adjust the dimension to which the %
unit points?
If not, what alternative approach would be more effective for animating the expansion/collapse of a container?
Here is an image showing the computed sizes of my collapsed element (with margin-top: -100%
):
https://i.sstatic.net/lybDS.png