Svetuka kune chikuru content Svetuka kuenda kudocs navigation
in English

Ratios

Shandisa pseudo zvinhu zvakagadzirwa kugadzira chinhu kuchengetedza chikamu chesarudzo yako. Yakakwana yekubata zvine mutsindo vhidhiyo kana masiraidhi embeds zvichienderana nehupamhi hwemubereki.

About

Shandisa reshiyo mubatsiri kutonga mareshiyo ezvekunze senge <iframe>s, <embed>s, <video>s, uye <object>s. Ava vabatsiri zvakare vanogona kushandiswa pane chero yakajairwa HTML mwana chinhu (semuenzaniso, a <div>kana <img>). Zvitaera zvinoiswa kubva .ratiokukirasi yevabereki zvakananga kumwana.

Aspect ratios inoziviswa mumepu yeSass uye inosanganisirwa mukirasi yega yega kuburikidza neCSS kusiyanisa, iyo inobvumirawo tsika yemaitiro ratios .

Pro-Tip! Iwe haudi frameborder="0"pane yako <iframe>sezvo isu tichipfuura izvo kwauri muReboot .

Muenzaniso

Putira chero embed, senge <iframe>, mune chinhu chemubereki chine .ratiouye chikamu chechiyero kirasi. Chinhu chemwana chiriporipo chinozvimisikidza saizi yekutenda kune yedu yepasirese yekusarudza .ratio > *.

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

Aspect ratios

Aspect ratios inogona kugadziridzwa ine modifier makirasi. Nekusagadzika makirasi eyero anotevera anopiwa:

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

Custom ratios

Kirasi yega .ratio-*yega inosanganisira CSS tsika pfuma (kana CSS kushanduka) mune yekusarudza. Iwe unogona kupfuudza iyi CSS chinja kuti ugadzire yakajairika mareshiyo panhunzi uine imwe inokurumidza math padivi pako.

Semuyenzaniso, kugadzira 2x1 aspect ratio, set --bs-aspect-ratio: 50%on the .ratio.

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

Iyi CSS inosiyana inoita kuti zvive nyore kugadzirisa chikamu chechiyero pane mabreakpoints. Izvi zvinotevera 4x3 kutanga, asi kuchinja kune tsika 2x1 panguva yepakati breakpoint.

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

Sass mepu

Mukati _variables.scssme, unogona kushandura mareshiyo aunoda kushandisa. Heino $ratio-aspect-ratiosmepu yedu yakagara iripo. Shandura mepu sezvaunoda uye unganidzazve Sass yako kuti uishandise.

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