Aspect Ratio
⟦Á médíá frámé thát préšérvéš ítš wídth-tó-héíght rátíó.~~~~~~~~~~~~~~~~~~~~⟧
- ⟦Brówšérš~~~⟧
- Chrome 123+Firefox 121+Safari 17.5+
- ⟦Tíér~~⟧
- 0
- ⟦Búñdlé çómpréššéd~~~~~~⟧
- 268 B
- ⟦Fórçéd láýóút búdgét~~~~~~~⟧
- 0 ms
- ⟦Áxé búdgét~~~~⟧
- 0
- ⟦ŠŠR çómpátíblé~~~~~⟧
- ⟦Ýéš~~⟧
- ⟦Públíšhéd çóñtráçt~~~~~~~⟧
- ⟦Téšt hárñéšš~~~~~⟧
⟦Pláýgróúñd~~~~⟧
16:9 · Cover
⟦Éxámpléš~~~⟧
Square
The default ratio is 1. A square frame crops a landscape image at the sides.
import { AspectRatio } from "@gunkin/uiify";
<AspectRatio>
<img src="/mountains.svg" width="640" height="400" alt="An amber sun above blue mountain ridges" />
</AspectRatio>Portrait
Set ratio to 4 / 5 for a portrait frame. The image keeps its proportions while filling the frame.
import { AspectRatio } from "@gunkin/uiify";
<AspectRatio ratio={4 / 5}>
<img src="/mountains.svg" width="640" height="400" alt="An amber sun above blue mountain ridges" />
</AspectRatio>Contain
Apply .uncropped { object-fit: contain; } to keep the whole image visible. The optional skin supplies the frame background.
import { AspectRatio } from "@gunkin/uiify";
<AspectRatio ratio={16 / 9}>
<img className="uncropped" src="/mountains.svg" width="640" height="400" alt="An amber sun above blue mountain ridges" />
</AspectRatio>⟦ÁPÍ~~⟧
AspectRatio
| ⟦Próp~~⟧ | ⟦Týpé~~⟧ | ⟦Défáúlt~~~⟧ | ⟦Déšçríptíóñ~~~~⟧ |
|---|---|---|---|
ratio | number | 1 | ⟦Póšítívé fíñíté wídth dívídéd bý héíght. Íñválíd ñúmbérš fáll báçk tó 1. Whéñ ómíttéd, thé ÇŠŠ çúštóm própértý çáñ šét thé rátíó.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~⟧ |
children | ReactNode | — | ⟦Çóñtéñt pláçéd íñšídé thé frámé. Íñtríñšíç çóñtéñt çáññót éñlárgé thé frámé.~~~~~~~~~~~~~~~~~~~~~~~~~~~⟧ |
className | string | — | ⟦Çlášš ápplíéd tó thé frámé róót.~~~~~~~~~~~~⟧ |
style | CSSProperties | — | ⟦Ñátívé róót štýléš, íñçlúdíñg --úíífý-ášpéçt-rátíó whéñ rátíó íš ómíttéd.~~~~~~~~~~~~~~~~~~~~~~~~~~⟧ |
ref | Ref<HTMLElement> | — | ⟦Réf fórwárdéd tó thé réñdéréd róót éléméñt.~~~~~~~~~~~~~~~~⟧ |
as | ElementType | "div" | ⟦Ñátívé éléméñt ór çómpóñéñt úšéd fór thé róót.~~~~~~~~~~~~~~~~~⟧ |
render | ReactElement | ((props, state) => ReactElement) | — | ⟦Répláçé thé réñdéréd róót whílé préšérvíñg ítš própš, réf áñd ídéñtítý márkér.~~~~~~~~~~~~~~~~~~~~~~~~~~~~⟧ |
⟦Kéýbóárd~~~⟧
| ⟦Kéý~~⟧ | ⟦Áçtíóñ~~~⟧ |
|---|
⟦Áççéššíbílítý~~~~~⟧
⟦Štátíç láýóút áddš ñó rólé, fóçúš tárgét ór kéýbóárd béhávíór. Gívé méáñíñgfúl ímágéš ált téxt; kéép çáptíóñš óútšídé thé frámé. Réqúíréd béhávíór ÇŠŠ préšérvéš thé rátíó évéñ whéñ çhíldréñ hávé íñtríñšíç díméñšíóñš. Óptíóñál štýléš fíll ímágéš wíth óbjéçt-fít: çóvér; úšé çóñtáíñ tó šhów thé éñtíré ímágé.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~⟧
⟦Štýlíñg hóókš~~~~~⟧
data-uiify-aspect-ratiodata-part="content"--uiify-aspect-ratio