Displays content within a desired ratio.
<div class="DemoContainer">
<AspectRatio.aspect_ratio ratio={16 / 9}>
<img
class="DemoImage"
src="https://images.unsplash.com/photo-1535025183041-0991a977e25b?w=300&dpr=2&q=80"
alt="Landscape photograph by Tobias Tullius"
/>
</AspectRatio.aspect_ratio>
</div>
.DemoContainer {
width: 300px;
border-radius: 6px;
overflow: hidden;
box-shadow: 0 2px 10px var(--black-a7);
}
.DemoImage {
object-fit: cover;
width: 100%;
height: 100%;
}
•
Accepts any custom ratio.
Anatomy
Import the component.
<AspectRatio.aspect_ratio />
Anatomy
-
Aspect Ratio - Contains the content you want to constrain to a given ratio.
API Reference
Aspect Ratio
Contains the content you want to constrain to a given ratio.
| Prop | Type | Default | Description |
|---|---|---|---|
ratio
|
float
|
1.0
|
ratio
Type
float
Default
1.0