AspectRatio
LayoutKeeps its content at a width-to-height ratio (16 / 9, 1, 4 / 3) as its width changes, so images and embeds don't shift the page while they load.
import { AspectRatio } from '@limerdev/zest'; Use for
Images, video and map embeds in a fluid layout.
Don't
Plain media with known width and height attributes: the browser keeps their ratio already.
Examples
Basic
The box keeps 16:9 as the page narrows.
16 : 9
<script lang="ts">
import { AspectRatio } from '@limerdev/zest';
</script>
<div class="w-full max-w-md">
<AspectRatio
ratio={16 / 9}
class="grid place-content-center rounded-box bg-base-300 text-sm text-muted"
>
16 : 9
</AspectRatio>
</div> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
AspectRatio
| Prop | Type | Default | Description |
|---|---|---|---|
| ratio | number | 1 | The aspect ratio of the image. |