Tsibela kumxholo ophambili Tsiba uye kukhangelo lwamaxwebhu
Check
in English

Imilinganiselo

Sebenzisa i-pseudo elements ezenziweyo ukwenza i-elementi igcine umlinganiselo wokhetho lwakho. Ifanelekile ukuphatha ividiyo okanye umboniso wesilayidi ngokusekwe kububanzi bomzali.

Malunga

Sebenzisa umncedisi wokulinganisa ukulawula umlinganiselo womxholo womxholo wangaphandle njengo <iframe>s, <embed>s, <video>s, kunye no <object>s. Aba bancedisi nabo banokusetyenziswa kuyo nayiphi na into eqhelekileyo ye-HTML yomntwana (umzekelo, a <div>okanye <img>). Izimbo zisetyenziswa ukusuka .ratiokwiklasi yabazali ukuya ngqo emntwaneni.

Aspect ratios ibhengezwe kwimaphu ye-Sass kwaye ibandakanywe kwiklasi nganye ngokuguquguquka kwe-CSS, ekwavumela umlinganiselo wenkalo eqhelekileyo .

Pro-Tip! Awudingi frameborder="0"kwi- <iframe>s yakho njengoko sibhala ngaphezulu kwakho kwi- Reboot .

Umzekelo

Songa naluphi na uzinziso, njenge <iframe>, kwisiqalelo somzali kunye .rationeklasi yomlinganiselo. Isiqalelo somntwana esikhawulezileyo senziwa ubungakanani ngokuzenzekela enkosi kumkhethi wethu jikelele .ratio > *.

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

Aspect ratios

Umyinge womlinganiselo unokwenziwa ngokweeklasi zesilungisi. Ngokungagqibekanga kubonelelwe ngezi klasi zilandelayo:

1x1
4x3
16x9
21x9
html
<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>

Ulungelelwaniso oluqhelekileyo

Iklasi nganye .ratio-*ibandakanya ipropati yesiko le-CSS (okanye i-CSS variable) kumkhethi. Ungayibhala ngaphezulu le CSS iguquguqukayo ukwenza ulungelelwaniso lwenkalo yesiko kubhabho ngezibalo ezikhawulezayo kwicala lakho.

Ngokomzekelo, ukwenza umlinganiselo we-2x1, usethe --bs-aspect-ratio: 50%kwi- .ratio.

2x1
html
<div class="ratio" style="--bs-aspect-ratio: 50%;">
  <div>2x1</div>
</div>

Oku kuguquguquka kwe-CSS kwenza kube lula ukulungisa umlinganiselo wembonakalo kuzo zonke iindawo zokuqhawula. Oku kulandelayo yi-4x3 ukuqala, kodwa utshintsho kwi-2x1 yesiko kwinqanaba eliphakathi.

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

Sass imephu

Ngaphakathi _variables.scss, ungatshintsha umlinganiselo wembonakalo ofuna ukuyisebenzisa. $ratio-aspect-ratiosNantsi imephu yethu ehlala ikho . Guqula imephu ngendlela othanda ngayo kwaye uqokelele iSass yakho ukuze uyisebenzise.

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