Margin
Margin utilities run 0 through 24 on the same 4px scale as padding.
--nc-space-4 is 1rem, so m-4 is one rem of margin in every direction.
Classes
Section titled “Classes”| Class pattern | Property |
|---|---|
m-0 … m-24 |
margin |
mx-* |
margin-inline |
my-* |
margin-block |
mt-* |
margin-top |
mr-* |
margin-right |
mb-* |
margin-bottom |
ml-* |
margin-left |
<div class="m-0">No margin</div><div class="mx-auto">Centered by inline margins</div><div class="mb-4">Space below</div>Auto margins
Section titled “Auto margins”Auto margins are m-auto, mx-auto, my-auto, mt-auto, mr-auto,
mb-auto, and ml-auto. mx-auto on a width-capped block is the usual
centering trick:
<main class="mx-auto max-w-50">Centered content</main>mt-auto is the common way to push a footer to the bottom of a flex column:
<div class="d-flex flex-column" style="min-block-size: 16rem"> <p>Content</p> <footer class="mt-auto">Footer</footer></div>Knob and responsive margin
Section titled “Knob and responsive margin”These classes are in the separate responsive module: import
nightcss/utilities/responsive after the base bundle, or use
nightcss/full.
The family reads --m, so one instance can use a one-off value:
<div class="m-4" style="--m: 37px">One-off margin</div>Responsive forms exist for m-*, mx-*, my-*, and the auto margins:
<div class="mx-2 mx-lg-auto">Centered from 1024px</div>Individual sides (mt-*, mr-*, mb-*, ml-*) are base-only; write a media
query when one side really needs to change.
When to use margin and when to use gap
Section titled “When to use margin and when to use gap”Prefer gap on a flex or grid parent over margins on children. A gap belongs to
the layout, survives wrapping, and cannot collapse. Reach for
Space Between when the children are prose or a plain
vertical list.
There are no negative spacing classes. When a surface has to escape its parent’s padding, use a negative margin in your own CSS:
.full-bleed { inline-size: 100vw; margin-inline: calc(50% - 50vw);}For inner spacing, see Padding.
Use in CSS
Section titled “Use in CSS”The class is the markup shorthand. The same style in a component stylesheet:
.section { margin-block: var(--nc-space-8);}.centered { margin-inline: auto;}The Sass subpackage exposes the same value: nc.nc-space(8). Auto centring
stays a literal margin-inline: auto; the accessor covers the scale steps. See
Sass subpackage.
A breakpoint is the same declaration inside a media query; you do not need a second class.