Trɔ yi nya veviwo gbɔ Trɔ yi docs ƒe mɔfiamewo dzi
in English

Nusiwo wotsɔ sɔ kple wo nɔewo

Zã pseudo elements siwo wowɔ be nàna element aɖe nalé aspect ratio si nètia la me ɖe asi. Enyo ŋutɔ na video alo slideshow embeds siwo wotu ɖe dzila ƒe kekeme dzi la gbɔ kpɔkpɔ nyuie.

Ku ɖe

Zã xexlẽme ƒe kpeɖeŋutɔa nàtsɔ akpɔ gotagome nyawo abe <iframe>s, <embed>s, <video>s, kple <object>s ene ƒe akpa ƒe sɔsɔmewo gbɔ. Woateŋu azã kpeɖeŋutɔ siawo hã ɖe HTML vi ƒe akpa ɖesiaɖe si wozãna ɖaa dzi (le kpɔɖeŋu me, a <div>alo <img>). Wozãa atsyãwo tso dzila .ratioƒe klass la me na ɖevia tẽ.

Woɖea gbeƒã akpa ƒe sɔsɔmewo le Sass ƒe anyigbatata me eye wotsɔa wo dea klass ɖesiaɖe me to CSS ƒe tɔtrɔ dzi, si hã ɖea mɔ ɖe akpa ƒe sɔsɔme siwo wowɔ ɖe ɖoɖo nu ŋu .

Pro-Aɖaŋuɖoɖo! Mehiã frameborder="0"le wò <iframe>s dzi abe alesi míeɖea asi le ema ŋu na wò le Reboot me ene o.

Kpɔɖeŋu

Bla embed ɖesiaɖe, abe <iframe>, ɖe dzila ƒe akpa aɖe me kple .ratiokple akpa ƒe xexlẽme ƒe hatsotso. Vi ƒe akpa si le enumake la ƒe lolome le eɖokui si akpe ɖe míaƒe xexeame katã ƒe tiatiawɔnu .ratio > *ŋu .

<div class="ratio ratio-16x9">
  <iframe src="https://www.youtube.com/embed/zpOULjyy-n8?rel=0" title="YouTube video" allowfullscreen></iframe>
</div>

Akpa ƒe akpawo ƒe sɔsɔme

Woate ŋu atrɔ asi le aspect ratios ŋu kple modifier classes. Le gɔmedzedzea me la, wotsɔ ratio ƒe hatsotso siwo gbɔna la na:

1x1 ƒe ƒuƒoƒo
4x3 ƒe ƒuƒoƒo
16x9 ƒe didime
21x9 ƒe didime
<div class="ratio ratio-1x1">
  <div>1x1</div>
</div>
<div class="ratio ratio-4x3">
  <div>4x3</div>
</div>
<div class="ratio ratio-16x9">
  <div>16x9</div>
</div>
<div class="ratio ratio-21x9">
  <div>21x9</div>
</div>

Dekɔnu ƒe xexlẽme ƒe sɔsɔme

Klas ɖesiaɖe .ratio-*dea CSS ƒe nɔnɔme tɔxɛ (alo CSS ƒe tɔtrɔ) ɖe tiatiawɔla la me. Àteŋu aɖe asi le CSS ƒe tɔtrɔ sia ŋu be nàwɔ akpa ƒe sɔsɔme tɔxɛwo le dzodzo me kple akɔntabubu kabakaba aɖewo le wò akpa dzi.

Le kpɔɖeŋu me, be nàwɔ 2x1 ƒe akpa ƒe sɔsɔme la, ɖoe --bs-aspect-ratio: 50%ɖe .ratio.

2x1 ƒe ƒuƒoƒo
<div class="ratio" style="--bs-aspect-ratio: 50%;">
  <div>2x1</div>
</div>

CSS ƒe tɔtrɔ sia na wòle bɔbɔe be woatrɔ asi le aspect ratio ŋu le breakpoints katã me. Nusi gbɔna nye 4x3 be woadze egɔme, gake etrɔna ɖe 2x1 si wowɔ ɖe ɖoɖo nu le titina ƒe gbagbãƒe.

.ratio-4x3 {
  @include media-breakpoint-up(md) {
    --bs-aspect-ratio: 50%; // 2x1
  }
}
4x3, emegbe 2x1
<div class="ratio ratio-4x3">
  <div>4x3, then 2x1</div>
</div>

Sass ƒe anyigbatata

Le _variables.scss, me la, àte ŋu atrɔ aspect ratio siwo nèdi be yeazã. Míaƒe $ratio-aspect-ratiosanyigbatata si míeɖo ɖi lae nye esi. Trɔ asi le anyigbatataa ŋu alesi nèdi eye nàgbugbɔ aƒo wò Sass nu ƒu be nàtsɔ wo ade dɔwɔwɔ me.

$aspect-ratios: (
  "1x1": 100%,
  "4x3": calc(3 / 4 * 100%),
  "16x9": calc(9 / 16 * 100%),
  "21x9": calc(9 / 21 * 100%)
);