AspectRatio
Keeps media at a shape, 16:9 by default.
An interactive page: C# runs over a Blazor Server connection.
Keeps its content at a fixed shape, such as 16:9 for a video or 1:1 for an avatar. Images and videos inside fill it and are cropped to fit.
Usage
<AspectRatio Ratio="16 / 9.0"><img src="..." alt="..." /></AspectRatio>Shapes
Use Ratio for the shape, width over height: the same picture at 16:9 (the default), 1:1 and 4:5, cropped to fill each.
Preview
16:9, the default
1:1
4:5
Code
<Grid Columns="3" Gap="4" Grow>
<Column Gap="2">
<AspectRatio Radius="Radius.Lg">Photo</AspectRatio>
<TextBlock Size="TextSize.Sm" Color="Color.Muted">16:9, the default</TextBlock>
</Column>
<Column Gap="2">
<AspectRatio Ratio="1" Radius="Radius.Lg">Photo</AspectRatio>
<TextBlock Size="TextSize.Sm" Color="Color.Muted">1:1</TextBlock>
</Column>
<Column Gap="2">
<AspectRatio Ratio="4 / 5.0" Radius="Radius.Lg">Photo</AspectRatio>
<TextBlock Size="TextSize.Sm" Color="Color.Muted">4:5</TextBlock>
</Column>
</Grid>Mode support
| Feature | Off | Static | Live |
|---|---|---|---|
| Everything | Yes | Yes | Yes |
Off: JavaScript disabled. Static: a static SSR page with IzzyBlazor's script. Live: an interactive page (Server, WebAssembly or Auto).
Accessibility
- It adds no name or role: an
imginside still needs itsalt, aniframeitstitle. - What doesn't fit the shape is cut off, not scrolled, so text inside can be lost when people zoom in.
Parameters
| Prop | Type | Default |
|---|---|---|
RatioWidth divided by height. | double | 1.7777777777777777 |
AsThe element to render: div on a Box; components built on it set their own (List a ul, Section a section). | string | "div" |
ChildContentThe content. | RenderFragment? |
Plus 25 surface props, 16 item props and 4 common props.
Full APISee also
- Image: a lazy image that keeps its space.
- VideoEmbed: a YouTube video that loads on play.
- Box: a plain block that takes every style prop.