object-fit
is an insanely great CSS property, which has surprisingly good browser support, but is lacking in the Edge/IE department. And Safari has some shortcomings as well.
There have been polyfills, which stopped working or just weren't that great, but this article has a new, much easier technique. I love it and am using it (in a little bit enhanced version) in a current project.