[ @sdxc/u/transform ]
translateY
Translates the element along the block axis using the spacing scale or a raw CSS length.
import { translateY } from "@sdxc/u/transform";Quick reference
Every documented call, beside the CSS it emits.
| Call | CSS |
|---|---|
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:
<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:
<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:
<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:
<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.
u.translateY("2.75rem")Applying on a state
Wrap the call in a state utility to scope it to one selector.
u.hover(u.translateY(4))Responsive design
Wrap the call in a container query to scope it to one width.
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:
:root {
--ui-spacing: 0.25rem;
}Every call that names the step now reads the new value:
translateY(4)Signature
u.translateY(value: SpacingValue)