I implemented this thing so many times, yet every time I try to do this again, I struggle.

The goal is simple: the modal needs to take at most x vh of vertical space and its content should scroll, when it doesn’t fit the container. Else, the entire modal should shrink vertically to take only the space that it needs.

Here’s the minimal example:

https://codepen.io/0ctothorp/pen/gOoRKXQ?editors=1100

The most important bits are:

Also, let’s not forget about our best friend: column flex. It makes everything easier to lay out inside the modal. Did you notice how I didn’t have to set any height value for the header, main and footer elements? Yet, everything sits exactly where it needs to be.

Hopefully this post proves itself helpful for me and/or you in the future 😉