Problem: equal height rows for responsive sites
Problem:
Keeping rows at equal heights when the viewport changes and blocks shift to new rows.
Requirements:
- Blocks of content must appear in a grid.
- The amount of blocks to a row needs to change according to the device width.
- The rows need to be equal heights.
- The blocks must be dynamic height (no max-height).
- The code and performance must be optimised for mobile.
Landscape Example
Portrait Example
Some ideas:
- Wrap every three elements and use the window resize event to change the wrap from 3 items to 2 using JavaScript.
- Duplicate the markup and show / hide each one using just CSS media queries.
- Don’t wrap the elements and use JavaScript’s windows resize event to match the heights of every group of 2 or 3 blocks.
What is the most efficient way of meeting these requirements using HTML / CSS / JavaScript?
Answers on a post code (or below or Twitter @joeyrabbitt).
Edit:
The team that encountered this problem eventually went for option 1 because it was the least memory intensive. It wasn’t favourable to have heavily duplicated markup on the page, so option 2 was ruled out. Option 3 was similar to option 1 in the way that it required JavaScript to loop through elements, but it was less intensive on to re-wrap elements as opposed to calculating individual heights and applying new inline styles to relevant items.

