Tlula eka nhlokomhaka-nkulu Tlula eka docs navigation
Check
in English

Ti-ratio

Tirhisa swiaki swa mavunwa leswi endliweke ku endla leswaku xiaki xi hlayisa mpimo wa xivumbeko lexi u xi hlawulaka. Swi hetisekile ku khoma hi ndlela leyi hlamulaka ku nghenisiwa ka vhidiyo kumbe ya nkombiso wa swilayidi hi ku ya hi ku anama ka mutswari.

Hi

Tirhisa mupfuni wa mpimo ku lawula swipimelo swa swiphemu swa nhundzu ya le handle ku fana na <iframe>s, <embed>s, <video>s, na <object>s. Vapfuni lava va nga tlhela va tirhisiwa eka elemente yihi na yihi ya n’wana ya HTML ya ntolovelo (xikombiso, a <div>kumbe <img>). Switayili swi tirhisiwa ku suka eka tlilasi ya mutswari .ratiohi ku kongoma eka n’wana.

Ti-aspect ratios ti tivisiwa eka mepe wa Sass naswona ti katsiwile eka tlilasi yin’wana na yin’wana hi ku tirhisa CSS variable, leswi tlhelaka swi pfumelela ti-aspect ratios ta ntolovelo .

Xitsundzuxo xa Pro-Tip! A wu lavi frameborder="0"eka s ya wena <iframe>tani hi leswi hi ku override sweswo eka Reboot .

Xikombiso

Pfuxeta embed yihi na yihi, ku fana na <iframe>, eka elemente ya mutswari na .rationa tlilasi ya aspect ratio. Xiphemu xa n'wana xa xihatla xi pimiwa hi ku tisungulela hikwalaho ka xihlawulekisi xa hina xa misava hinkwayo .ratio > *.

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

Swipimelo swa swiphemu

Ti aspect ratios tinga endliwa hi ku landza swilaveko hi titlilasi ta modifier. Hi ku tiyimisela ku nyikiwile titlilasi ta mpimo leti landzelaka:

1x1
4x3
16x9 hi ku
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>

Swiringanyeto swa ntolovelo

Tlilasi yin’wana na yin’wana .ratio-*yi katsa nhundzu ya ntolovelo ya CSS (kumbe xihlawulekisi xa CSS) eka xihlawulekisi. U nga ha tlula xihlawulekisi lexi xa CSS ku tumbuluxa ti-aspect ratio ta ntolovelo hi ku hatlisa hi tinhlayo tin’wana to hatlisa eka xiphemu xa wena.

Hi xikombiso, ku endla mpimo wa xivumbeko xa 2x1, veka --bs-aspect-ratio: 50%eka .ratio.

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

Xihlawulekisi lexi xa CSS xi endla leswaku swi olova ku cinca mpimo wa xivumbeko ku tsemakanya tindhawu to wisa. Leswi landzelaka i 4x3 ku sungula, kambe swi cinca ku ya eka 2x1 ya ntolovelo eka ndhawu yo wisa ya le xikarhi.

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

Mepe wa Sass

Endzeni ka _variables.scss, u nga cinca ti- aspect ratio leti u lavaka ku ti tirhisa. $ratio-aspect-ratiosHi lowu mepe wa hina wa ntolovelo . Cinca mepe hilaha u lavaka hakona ivi u tlhela u hlengeleta Sass ya wena leswaku u yi tirhisa.

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