sdxc

[ @sdxc/u/layout ]

top

Applies the physical top property, for offsets genuinely tied to the viewport's top side.

import { insTop } from "@sdxc/u/layout";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.insTop(4)css({ top: "calc(var(--ui-spacing, 0.25rem) * 4)" })

Examples

Basic example

Use insTop(n) to set the top offset of a positioned element from the spacing scale:

insTop(0)
insTop(6)
<div mix={[...]}>
	<div mix={[relative(), is(48), bs(32), ...]}>
		<div mix={[absolute(), insTop(0), ...]}>insTop(0)</div>
	</div>
	<div mix={[relative(), is(48), bs(32), ...]}>
		<div mix={[absolute(), insTop(6), ...]}>insTop(6)</div>
	</div>
</div>

Placing below the parent

Use insTop("full") to place an element right below its positioned parent, like a menu under its button:

Menu
<div mix={[bs(36)]}>
	<div mix={[relative()]}>
		<button type="button" mix={[...]}>
			Options
		</button>
		<div mix={[absolute(), insTop("full"), insLeft(0), mbs(2), is(40), ...]}>Menu</div>
	</div>
</div>

Using a custom value

Every scale argument also takes a raw CSS value, which passes through untouched.

u.insTop("2.75rem")

Applying on a state

Wrap the call in a state utility to scope it to one selector.

u.hover(u.insTop(4))

Responsive design

Wrap the call in a container query to scope it to one width.

u.at("md", u.insTop(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:

insTop(4)

Signature

u.insTop(value: SizeValue)

Written by Sergio Xalambrí. Follow @sergiodxa for new packages, or sponsor the work.