[ @sdxc/u/size ]
aspect-ratio
Applies aspect-ratio, either from a width/height pair or one of the named ratios in AspectRatioName.
import { aspect } from "@sdxc/u/size";Quick reference
Every documented call, beside the CSS it emits.
| Call | CSS |
|---|---|
u.aspect(16, 9) | css({ aspectRatio: "16 / 9" }) |
u.aspect("square") | css({ aspectRatio: "1 / 1" }) |
Examples
Basic example
Use aspect(width, height) to give an element a fixed aspect ratio, like aspect(16, 9) for a video frame:
<div mix={[aspect(16, 9), is(80), ...]} />Named ratios
Pass a name for the common shapes: "square", "photo", "video", "widescreen", "portrait" or "story":
square
photo
video
widescreen
portrait
story
<div mix={[...]}>
<div mix={[aspect("square"), is(28), ...]}>square</div>
<div mix={[aspect("photo"), is(28), ...]}>photo</div>
<div mix={[aspect("video"), is(28), ...]}>video</div>
<div mix={[aspect("widescreen"), is(28), ...]}>widescreen</div>
<div mix={[aspect("portrait"), is(28), ...]}>portrait</div>
<div mix={[aspect("story"), is(28), ...]}>story</div>
</div>Applying on a state
Wrap the call in a state utility to scope it to one selector.
u.hover(u.aspect(16, 9))Responsive design
Wrap the call in a container query to scope it to one width.
u.at("md", u.aspect(16, 9))Signature
u.aspect(ratio: AspectRatioName)