Sidebar layout

사이드바 레이아웃

A fixed-width sidebar plus a main area that fills the rest — with no media query, it stacks vertically on its own once space runs out.

Also known as: Every Layout Sidebar
···
html
<div class="stage" id="stage">
  <div class="sidebar-demo">
    <div class="side">Sidebar<br><span>flex-basis: 12rem</span></div>
    <div class="content">Content<br><span>flex-grow: 999; min-width: 50%</span></div>
  </div>
</div>
css
.stage{width:26%;min-width:90px;max-width:92%;transition:width 2.8s cubic-bezier(.4,0,.2,1)}
.stage.wide{width:92%}
.sidebar-demo{display:flex;flex-wrap:wrap;gap:10px;width:100%}
.side{flex-basis:74px;flex-grow:1;background:var(--accent);color:#fff;border-radius:8px;
  display:grid;place-items:center;text-align:center;font-size:10px;font-weight:700;min-height:64px;padding:6px}
.content{flex-basis:0;flex-grow:999;min-width:50%;background:var(--surface);border:1px solid var(--line);
  border-radius:8px;display:grid;place-items:center;text-align:center;font-size:10px;font-weight:700;
  color:var(--muted);min-height:64px;padding:6px}
.side span,.content span{display:block;font-weight:400;font-size:8px;opacity:.85;margin-top:4px}
js
const stage = document.getElementById('stage');
setInterval(() => stage.classList.toggle('wide'), 2400);

The usual way to make "sidebar plus content" responsive is a hardcoded breakpoint: @media (max-width: 768px) { flex-direction: column }. But when this layout should actually stack depends on the combined minimum widths the sidebar and content need — not on the viewport size — and a media query has no idea about that.

Every Layout's trick hands that judgment to CSS itself with three declarations: display: flex; flex-wrap: wrap on the parent, flex-basis: 12rem on the sidebar, and flex-basis: 0; flex-grow: 999; min-width: 50% on the content. The content's flex-grow: 999 means "take almost all the leftover space when there is any"; min-width: 50% means "wrap to the next line once my available width drops below half the container." Where those two conditions collide, flex-wrap fires automatically.

The advantage is that "how narrow before it stacks" is a single number (the min-width percentage) scaled to the container's own size. Drop the same sidebar component into a full-width page or a narrow modal, and it responds correctly in either context — a pure-CSS, container-aware solution that predates container queries.

When to use

Use it for a secondary region that's narrower and closer to a fixed width than the main content — an app shell's nav sidebar, a table of contents beside an article, an options panel next to a product page. If the sidebar must stay pinned while scrolling, pair it with position: sticky.