[ @sdxc/u/overflow ]
scroll-padding
Applies logical scroll-padding so a scroll snap position or anchor jump lands clear of a sticky header — set it to the header's height.
import { scrollPadding } from "@sdxc/u/overflow";Quick reference
Every documented call, beside the CSS it emits.
| Call | CSS |
|---|---|
u.scrollPadding(4) | css({ scrollPadding: "calc(var(--ui-spacing, 0.25rem) * 4)" }) |
u.scrollPadding(16, 0) | css({ scrollPaddingBlock: "...", scrollPaddingInline: "..." }) |
Examples
Basic example
Use scrollPadding(n) on a scroll container to keep anchor jumps and snap positions clear of a sticky header. Click a link and the section stops below the header:
<div mix={[vstack({ gap: 4 }), is(72), maxIs("100%")]}>
<nav mix={[hstack({ gap: 3 })]}>
<a href="#padded-1">Section 1</a>
<a href="#padded-2">Section 2</a>
<a href="#padded-3">Section 3</a>
</nav>
<div
mix={[
scroll("y"),
scrollPadding(14),
vstack({ gap: 3 }),
bs(56),
pi(4),
pbe(4),
...,
]}
>
<header mix={[sticky(), insBs(0), bg(), p(3), ...]}>Sticky header</header>
<section id="padded-1" mix={[shrink(), bs(32), ...]}>
Section 1
</section>
<section id="padded-2" mix={[shrink(), bs(32), ...]}>
Section 2
</section>
<section id="padded-3" mix={[shrink(), bs(32), ...]}>
Section 3
</section>
</div>
</div>Insetting snap positions
Pass a block and an inline value, like scrollPadding(0, 8), to inset where items snap along a carousel. Scroll the row and each card settles away from the edge:
<div
mix={[
scroll("x"),
scrollSnapType(),
scrollPadding(0, 8),
hstack({ gap: 4 }),
is(96),
maxIs("100%"),
p(4),
...,
]}
>
<div mix={[scrollSnapAlign(), shrink(), is(56), bs(32), ...]}>1</div>
<div mix={[scrollSnapAlign(), shrink(), is(56), bs(32), ...]}>2</div>
<div mix={[scrollSnapAlign(), shrink(), is(56), bs(32), ...]}>3</div>
<div mix={[scrollSnapAlign(), shrink(), is(56), bs(32), ...]}>4</div>
</div>Using a custom value
Every scale argument also takes a raw CSS value, which passes through untouched.
u.scrollPadding("2.75rem")Applying on a state
Wrap the call in a state utility to scope it to one selector.
u.hover(u.scrollPadding(4))Responsive design
Wrap the call in a container query to scope it to one width.
u.at("md", u.scrollPadding(4))Customizing your theme
Customizing spacing
Every numeric step multiplies --ui-spacing, so redefining it rescales every spacing and sizing utility at once:
:root {
--ui-spacing: 0.25rem;
}Every call that names the step now reads the new value:
scrollPadding(4)Signature
u.scrollPadding(...values: SpacingValue[])