Responsive Two-column Grid
suggest changeCSS Grid directly expresses a main-content and sidebar layout:
<div class="page-layout">
<main>…</main>
<aside>…</aside>
</div>
.page-layout {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(14rem, 20rem);
gap: 2rem;
}
@media (width < 48rem) {
.page-layout {
grid-template-columns: 1fr;
}
}
minmax(0, 1fr) lets the main column shrink below the intrinsic width of long content instead of overflowing. Both columns stretch to the grid row's height by default. The range media-query syntax stacks the columns in narrower viewports.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents