sdxc

[ @sdxc/u/transform ]

rotateX

Rotates the element in 3D around its horizontal axis for a flip-card or page-turn effect.

import { rotateX } from "@sdxc/u/transform";

Quick reference

Every documented call, beside the CSS it emits.

CallCSS
u.rotateX(180)css({ "--ui-rotate-x": "180deg", transform: "... rotateX(var(--ui-rotate-x, 0deg)) ..." })

Examples

Basic example

Use rotateX(n) with a number of degrees to tip an element around its horizontal axis, and perspective() on the parent to give it depth:

rotateX(30)
rotateX(50)
rotateX(-50)
<div mix={[...]}>
	<div mix={[perspective(400), ...]}>
		<div mix={[rotateX(30), ...]}>rotateX(30)</div>
	</div>
	<div mix={[perspective(400), ...]}>
		<div mix={[rotateX(50), ...]}>rotateX(50)</div>
	</div>
	<div mix={[perspective(400), ...]}>
		<div mix={[rotateX(-50), ...]}>rotateX(-50)</div>
	</div>
</div>

Adding perspective

Without a perspective() on the parent, rotateX() reads as a flat vertical squash; with one, the far edge recedes:

flat
perspective(300)
<div mix={[...]}>
	<div mix={[...]}>
		<div mix={[rotateX(55), ...]}>flat</div>
	</div>
	<div mix={[perspective(300), ...]}>
		<div mix={[rotateX(55), ...]}>perspective(300)</div>
	</div>
</div>

Flipping on hover

Combine it with hover() and a transition("transform") to flip an element over. Hover the tile to try it:

hover me
<div mix={[...]}>
	<div mix={[perspective(400), ...]}>
		<div mix={[hover(rotateX(180)), transition("transform", { duration: 500 }), ...]}>
			hover me
		</div>
	</div>
</div>

Using a custom value

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

u.rotateX("2.75rem")

Applying on a state

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

u.hover(u.rotateX(180))

Responsive design

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

u.at("md", u.rotateX(180))

Signature

u.rotateX(value: AngleValue)

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