Content-sized Sidebar with Grid
suggest changeUse a max-content track when one column should take only the space its content needs and the other should fill the remainder:
.layout {
display: grid;
grid-template-columns: max-content minmax(0, 1fr);
gap: 1.5rem;
align-items: start;
}
@media (width < 40rem) {
.layout {
grid-template-columns: 1fr;
}
}
max-content sizes the sidebar from its contents. minmax(0, 1fr) gives the content column the remaining space while allowing it to shrink. If the sidebar's intrinsic width might be excessive, constrain it:
.layout > aside {
max-inline-size: min(20rem, 100%);
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents