I am creating a responsive grid of images. Each row has two images—one rectangular, and one square—and the layout is reversed for each row (square
rectangle
-> rectangle
square
, and so on).
Currently, I am using height: 0; padding-bottom: 100%
to make my square div keep its ratio, and the rectangular div gets height: 100%; padding-bottom: 0;
. It works completely fine, until there's a case where the last image in the gallery is a rectangular div on its own row. The height: 100%;
no longer has any height to work with, so it ends up with no height at all.
I have recreated my issue in this CodePen: https://codepen.io/Dalen_K/pen/GRvdEjp
How can I ensure that the last div maintains the same height that it would have if it had a square next to it (preferably without JS)? Would a grid work better for this than flexbox? If so, how would I go about doing it?
Thanks in advance!