Display
Aspect Ratio
Locks its content to a fixed width/height ratio, so media reserves its space before it loads.
Installation #
With the Nuxt module, every component is auto-imported — there is nothing to add. In a plain Vue project, import what you use:
Copy
import { JAspectRatio } from '@juxtui/ui'Usage #
Copy
<JAspectRatio :ratio="16 / 9" class="overflow-hidden rounded-lg">
<img src="/cover.jpg" alt="" class="h-full w-full object-cover" />
</JAspectRatio>The component only reserves the box — rounding, overflow-hidden and the fit of the content are yours, via class on the root. Content is stretched to fill with object-fit: cover for img, video, iframe and canvas children automatically.
Variants & examples #
A 1:1 grid#
Three equal thumbnails, each ratio-locked.
Wide video frame#
A 21:9 ratio for a cinematic player placeholder.
21:9 video player
API #
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| ratio | number | 16 / 9 | Width/height ratio, e.g. 16 / 9 or 1. |
Slots
| Slot | Props | Description |
|---|---|---|
| default | — | The content to lock to the ratio, typically an image or video. |
Accessibility #
- A plain
<div>with no implicit role — any semantics come entirely from the content you put inside it, e.g.alttext on animg.