Aspect Ratio
Displays content within a desired ratio.
Preview
A preview of the Aspect Ratio component with interactive controls.
Interactive
Installation
Add the Aspect Ratio component to your project.
ng g @ng-cn/core:c aspect-ratioUsage
Import and use the Aspect Ratio component in your Angular application.
<div class="w-full max-w-md">
<AspectRatio [ratio]="16 / 9" class="bg-muted rounded-lg overflow-hidden">
<img
src="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?w=800&dpr=2&q=80"
alt="Photo by Drew Beamer"
class="h-full w-full object-cover"
/>
</AspectRatio>
</div>Examples
Explore different variations and use cases for the Aspect Ratio component.
Basic
Interactive
Square
Interactive
API Reference
Props | Prop | Type | Default | Description |
|---|---|---|---|
ratio | number | 1 | The desired aspect ratio. |
class | string | — | Additional CSS classes to apply. |