Media gallery
Keep image tiles the same shape while assets load.
Components / Layout
A CSS aspect-ratio wrapper for media and previews.
Designing calmer project handoffs
A 16:9 media card that stays stable at every width.
Keep image tiles the same shape while assets load.
Preserve a widescreen preview inside a flexible card.
<AspectRatio :ratio="4 / 3">
<img src="/preview.jpg" alt="Project preview" />
</AspectRatio>The wrapper sets shape while the image fills it.
<script setup lang="ts">
import AspectRatio from './components/ui/aspect-ratio/AspectRatio.vue'
</script>
<template>
<AspectRatio :ratio="4 / 3" as="figure">
<img src="/gallery/mountains.jpg" alt="Mountain landscape" class="h-full w-full object-cover" />
</AspectRatio>
</template>A string ratio can represent a familiar format.
<script setup lang="ts">
import AspectRatio from './components/ui/aspect-ratio/AspectRatio.vue'
</script>
<template>
<AspectRatio ratio="16 / 9"><video controls src="/demo.mp4" class="h-full w-full" /></AspectRatio>
</template>The most useful props, models, slots, events, and methods for this component.
| Name | Type | Default or requirement |
|---|---|---|
ratio | number | string | 16 / 9 |
as | div | figure | div |
Give images meaningful alternative text when they convey information.