On my website, users can upload pictures. They can be of various sizes, but I want them to fit in boxes of the same height, so they can be put next to each other and form a grid. The image should be centered in the box, keeping it's aspect ratio. Can I do this in CSS? I've been trying things with flexbox, but I can't make it work.
e.g.
If height is larger than width:
|-------------|
| imageim |
| ageimag |
| eimagei |
| mageima |
| geimage |
| imageim |
|-------------|
If width is larger than height:
|-------------|
| |
|imageimageima|
|geimageimagei|
|mageimageimag|
|eimageimageim|
| |
|-------------|