Alpha
Fits as many columns as the container allows.
NightCSS ships two grid systems. The native one — .grid, .grid-cols-*, and
.col-span-* — is the default for new layouts. The 12-column row / col grid
is a flexbox system with breakpoint suffixes, useful when porting markup that
already speaks in columns.
.grid sets display: grid. .grid-cols-1 through .grid-cols-24 create equal
columns with repeat(n, minmax(0, 1fr)), so long content cannot blow out a track.
.col-span-1 through .col-span-24 place an item across tracks.
<div class="grid grid-cols-3 gap-4"> <div>One</div> <div>Two</div> <div class="col-span-2">Spans two</div></div>Use gap-* for spacing. Avoid margins on grid children; the gap is the layout,
and margins fight it.
<div class="grid grid-cols-12 gap-4"> <main class="col-span-8">Primary content</main> <aside class="col-span-4">Secondary content</aside></div>main · col-span-8
Primary content.
Twelve columns are too narrow on a phone. Write the responsive version in CSS:
.page { display: grid; gap: var(--nc-space-4);}
@media (min-width: 48rem) { .page { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.page > main { grid-column: span 8; }
.page > aside { grid-column: span 4; }}The source order stays the same: main first, aside second. On narrow screens both
stack. Do not use order to put content in a different visual order unless the
DOM order is also correct for keyboard and screen-reader users.
The most useful pattern needs no breakpoints. Let the columns fit themselves:
<div class="grid gap-4" style="grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr))"> <article>Alpha</article> <article>Beta</article> <article>Gamma</article></div>Fits as many columns as the container allows.
No media query.
The track minimum is the breakpoint.
min(14rem, 100%) is the important part: on a container narrower than 14rem,
the track becomes 100% instead of overflowing. Use auto-fill instead of
auto-fit when you want empty tracks to keep the card width.
Viewport media queries are the wrong tool for a component that appears in different slots. A container query responds to the space the component actually has:
.card-grid { container-type: inline-size; display: grid; gap: var(--nc-space-4);}
@container (min-width: 40rem) { .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }}Container queries cannot read custom properties, so --nc-breakpoint-* is not
usable inside @container. Write the literal value.
The row / col grid is a 12-column flexbox system. row wraps its children
and pulls the gutters out with a negative inline margin; every column adds
--nc-space-2 of inline padding.
| Class | Effect |
|---|---|
row |
display: flex; flex-wrap: wrap with negative gutters |
col |
Equal-width flexible column |
col-1 … col-12 |
Fixed width, 1/12 to 12/12 |
offset-0 … offset-12 |
Left margin in twelfths |
order-1 … order-12 |
order value |
<div class="row"> <div class="col-4">4/12</div> <div class="col-8">8/12</div></div>Responsive: col-md-6, offset-lg-2, order-xl-1, and so on. The breakpoint
goes before the number and the pattern is the same at every step.
These classes are in the separate responsive module: import
nightcss/utilities/responsive after the base bundle, or use
nightcss/full.
<div class="row"> <div class="col-12 col-md-6 col-lg-4">…</div> <div class="col-12 col-md-6 col-lg-4">…</div> <div class="col-12 col-md-12 col-lg-4">…</div></div>| Token | Value |
|---|---|
--nc-breakpoint-sm |
640px |
--nc-breakpoint-md |
768px |
--nc-breakpoint-lg |
1024px |
--nc-breakpoint-xl |
1280px |
--nc-breakpoint-2xl |
1536px |
In plain CSS, write the value (48rem is 768px at the default root size). In
Sass, use nc-media-up("md").
order on interactive content to reverse it.320px and at 200% zoom. minmax(0, 1fr) and min() prevent most
overflow, but long unbroken strings still need overflow-wrap.