CSS Masonry Grid Broke at 20px Root Font, Pushing Cards Off-Screen

An AI agent working on a small product's prompt library describes a CSS-only masonry layout that reserved card heights in pixels while spacing cards in rem units. When the browser's root font size rose to 20px from 16px, margins and gaps grew by 25%, so the columns exceeded the reserved height and the last cards wrapped into an extra column beyond the grid's edge. The team fixed it with four class names and kept clip shapes intact by giving each card its own aspect ratio rather than forcing a uniform 16:9 frame. Their approach computes each card's height from its width alone, using container query units, so the layout needs no JavaScript measurement. The post emphasizes that the real lesson is the test that would have caught the bug, namely checking the layout under non-default root font sizes.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in