Hla mus rau cov ntsiab lus tseem ceeb Hla mus rau docs navigation
in English

Piv txwv

Siv cov ntsiab lus pseudo generated los ua ib qho kev tswj xyuas qhov sib piv ntawm koj xaiv. Zoo meej rau kev daws cov yees duab lossis slideshow embeds raws li qhov dav ntawm niam txiv.

Txog

Siv tus pab cuam piv los tswj qhov sib piv ntawm cov ntsiab lus sab nraud xws li <iframe>s, <embed>s, <video>s, thiab <object>s. Cov pab cuam no kuj tuaj yeem siv tau rau txhua tus qauv HTML menyuam lub caij (piv txwv li, ib <div>lossis <img>). Cov qauv siv los ntawm cov chav kawm niam txiv .rationcaj qha rau tus menyuam.

Aspect ratios tau tshaj tawm nyob rau hauv daim ntawv qhia Sass thiab suav nrog hauv txhua chav kawm ntawm CSS kuj sib txawv, uas kuj tso cai rau kev cai nam piv .

Pro-Tip! Koj tsis xav tau frameborder="0"ntawm koj <iframe>li peb override uas rau koj hauv Reboot .

Piv txwv

Qhwv tej embed, zoo li ib tug <iframe>, nyob rau hauv ib tug niam txiv keeb nrog .ratiothiab ib tug nam piv chav kawm ntawv. Lub caij me nyuam tam sim ntawd tau txais qhov loj me ua tsaug rau peb tus neeg xaiv thoob ntiaj teb .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 tuaj yeem kho nrog cov chav kawm hloov kho. Los ntawm lub neej ntawd cov chav kawm piv txwv hauv qab no tau muab:

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

Kev cai piv

Txhua .ratio-*chav kawm suav nrog CSS cov cuab yeej kev cai (lossis CSS sib txawv) hauv tus xaiv. Koj tuaj yeem hla dhau qhov sib txawv CSS no los tsim cov kev cai nam piv ntawm ya nrog qee tus lej ceev ntawm koj qhov.

Piv txwv li, los tsim 2x1 nam piv, teem --bs-aspect-ratio: 50%rau ntawm .ratio.

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

Qhov kev hloov pauv CSS no ua rau nws yooj yim los hloov kho qhov piv txwv hla cov ntsiab lus tawg. Cov hauv qab no yog 4x3 pib, tab sis hloov mus rau kev cai 2x1 ntawm qhov nruab nrab breakpoint.

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

Sass map

Tsis pub dhau _variables.scss, koj tuaj yeem hloov pauv qhov piv txwv uas koj xav siv. Nov yog peb $ratio-aspect-ratiosdaim ntawv qhia ua ntej. Hloov kho daim ntawv qhia raws li koj nyiam thiab rov muab koj Sass tso rau lawv siv.

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