SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

translateY

Translates the element along the block axis using the spacing scale or a raw CSS length.

tsx
import { translateY } from "@sdxc/u/transform";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.translateY(4)css({ "--ui-translate-y": "calc(var(--ui-spacing, 0.25rem) * 4)", transform: "translate(var(--ui-translate-x, 0), var(--ui-translate-y, 0)) ..." })

Examples

Basic example

Use translateY(n) with a step of the spacing scale, like translateY(2) or translateY(6), to move an element vertically:

translateY(2)
translateY(6)
tsx
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[translateY(2), ...]}>translateY(2)</div>
	</div>
	<div mix={[...]}>
		<div mix={[translateY(6), ...]}>translateY(6)</div>
	</div>
</div>

Using negative values

Pass a negative step, like translateY(-6), to move an element up:

translateY(-2)
translateY(-6)
tsx
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[translateY(-2), ...]}>translateY(-2)</div>
	</div>
	<div mix={[...]}>
		<div mix={[translateY(-6), ...]}>translateY(-6)</div>
	</div>
</div>

Using percentages and lengths

Pass a string for any CSS length; a percentage like translateY("-25%") is a share of the element's own height:

translateY("-25%")
translateY("12px")
tsx
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[translateY("-25%"), ...]}>translateY("-25%")</div>
	</div>
	<div mix={[...]}>
		<div mix={[translateY("12px"), ...]}>translateY("12px")</div>
	</div>
</div>

Lifting on hover

Combine it with hover() and a transition("transform") to lift a card under the pointer. Hover the card to try it:

Hover to lift this card
tsx
<div mix={[hover(translateY(-1)), transition("transform"), ...]}>
	Hover to lift this card
</div>

Using a custom value

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

typescript
u.translateY("2.75rem")

Applying on a state

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

typescript
u.hover(u.translateY(4))

Responsive design

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

typescript
u.at("md", u.translateY(4))

Customizing your theme

Customizing spacing

Every numeric step multiplies --ui-spacing, so redefining it rescales every spacing and sizing utility at once:

css
:root {
	--ui-spacing: 0.25rem;
}

Every call that names the step now reads the new value:

typescript
translateY(4)

Signature

typescript
u.translateY(value: SpacingValue)
@sdxc/u

Can’t find it? Contact us