Bootstrap 4 Flex
Bootstrap 4 Flex
Pomocí tříd flex můžete ovládat rozložení komponent Bootstrap 4.
Flexbox
Největší rozdíl mezi Bootstrap 3 a Bootstrap 4 je v tom, že Bootstrap 4 nyní ke zpracování rozvržení používá flexbox namísto plovoucích.
Flexibilní modul rozvržení krabice usnadňuje navrhování flexibilní struktury rozvržení, která reagují, bez použití plovoucího nebo polohování. Pokud s flexem začínáte, můžete si o něm přečíst v našem CSS Flexbox Tutorial .
Poznámka: Flexbox není podporován v IE9 a starších verzích.
Pokud požadujete podporu IE8-9, použijte Bootstrap 3. Je to nejstabilnější verze Bootstrapu a tým je stále podporován pro kritické opravy chyb a změny dokumentace. Nebudou do ní však přidávány žádné nové funkce.
Chcete-li vytvořit kontejner flexbox a přeměnit přímé potomky na flex položky, použijte d-flex
třídu:
Příklad
Příklad
<div class="d-flex p-3 bg-secondary text-white">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex
item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Chcete-li vytvořit vložený kontejner flexbox, použijte d-inline-flex
třídu:
Příklad
Příklad
<div class="d-inline-flex p-3 bg-secondary text-white">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex
item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Horizontální směr
Použijte .flex-row
k zobrazení flexibilních položek vodorovně (vedle sebe). Toto je výchozí nastavení.
Tip: Použijte .flex-row-reverse
k zarovnání vodorovného směru doprava:
Příklad
Příklad
<div class="d-flex flex-row
bg-secondary">
<div class="p-2 bg-info">Flex
item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
<div
class="d-flex flex-row-reverse bg-secondary">
<div class="p-2 bg-info">Flex
item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Vertikální směr
Použijte .flex-column
k zobrazení flexibilních položek svisle (nad sebou) nebo .flex-column-reverse
k obrácení svislého směru:
Příklad
Příklad
<div class="d-flex flex-column">
<div class="p-2 bg-info">Flex
item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
<div
class="d-flex flex-column-reverse">
<div class="p-2 bg-info">Flex
item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Zarovnat obsah
Pomocí .justify-content-*
tříd změňte zarovnání flexibilních položek. Platné třídy jsou start
(výchozí) , end
, nebo :center
between
around
Příklad
Příklad
<div class="d-flex justify-content-start">...</div>
<div class="d-flex
justify-content-end">...</div>
<div class="d-flex
justify-content-center">...</div>
<div class="d-flex
justify-content-between">...</div>
<div class="d-flex
justify-content-around">...</div>
Vyplnit / Stejné šířky
Použijte .flex-fill
na ohebné předměty, abyste je donutili do stejných šířek:
Příklad
Příklad
<div class="d-flex">
<div class="p-2 bg-info
flex-fill">Flex
item 1</div>
<div class="p-2 bg-warning flex-fill">Flex item 2</div>
<div class="p-2 bg-primary flex-fill">Flex item 3</div>
</div>
Růst
Použijte .flex-grow-1
na ohebný předmět, abyste zabrali zbytek místa. V níže uvedeném příkladu první dvě flexibilní položky zabírají potřebné místo, zatímco poslední položka zabírá zbytek dostupného místa:
Příklad
Příklad
<div class="d-flex">
<div class="p-2 bg-info">Flex
item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary flex-grow-1">Flex item 3</div>
</div>
Tip: Použijte .flex-shrink-1
na ohebný předmět, aby se v případě potřeby srazil.
Objednat
Změňte vizuální pořadí konkrétních flexibilních položek pomocí .order
tříd. Platné třídy jsou od 0 do 12, kde nejnižší číslo má nejvyšší prioritu (pořadí-1 se zobrazuje před pořadím-2 atd.):
Příklad
Příklad
<div class="d-flex bg-secondary">
<div class="p-2 bg-info
order-3">Flex
item 1</div>
<div class="p-2 bg-warning order-2">Flex item 2</div>
<div class="p-2 bg-primary order-1">Flex item 3</div>
</div>
Automatické okraje
Snadno přidávejte automatické okraje k ohebným položkám pomocí .mr-auto
(posunout položky doprava) nebo pomocí .ml-auto
(posunout položky doleva):
Příklad
Příklad
<div class="d-flex
bg-secondary">
<div class="p-2 mr-auto bg-info">Flex
item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
<div class="d-flex bg-secondary">
<div
class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex
item 2</div>
<div class="p-2 ml-auto bg-primary">Flex item
3</div>
</div>
Zabalit
Ovládejte, jak se flexibilní položky zabalí do flexibilního kontejneru, pomocí .flex-nowrap
(výchozí) .flex-wrap
nebo .flex-wrap-reverse
.
Kliknutím na tlačítka níže zobrazíte rozdíl mezi těmito třemi třídami změnou balení flexibilních položek v rámečku příkladu:
Příklad
Příklad
<div class="d-flex flex-wrap">..</div>
<div class="d-flex
flex-wrap-reverse">..</div>
<div class="d-flex
flex-nowrap">..</div>
Zarovnat obsah
Ovládejte vertikální zarovnání shromážděných pružných položek s .align-content-*
třídami. Platné třídy jsou .align-content-start
(výchozí) , .align-content-end
, .align-content-center
, .align-content-between
a .align-content-around
..align-content-stretch
Poznámka: Tyto třídy nemají žádný vliv na jednotlivé řádky flexibilních položek.
Příklad
Příklad
<div class="d-flex flex-wrap
align-content-start">..</div>
<div class="d-flex
flex-wrap align-content-end">..</div>
<div class="d-flex
flex-wrap align-content-center">..</div>
<div class="d-flex
flex-wrap align-content-around">..</div>
<div class="d-flex
flex-wrap align-content-stretch">..</div>
Zarovnat položky
Ovládejte vertikální zarovnání jednotlivých řad flexibilních položek s .align-items-*
třídami. Platné třídy jsou .align-items-start
, .align-items-end
, .align-items-center
, .align-items-baseline
a .align-items-stretch
(výchozí).
Kliknutím na tlačítka níže zobrazíte rozdíl mezi těmito pěti třídami:
Příklad
Příklad
<div class="d-flex align-items-start">..</div>
<div class="d-flex
align-items-end">..</div>
<div class="d-flex
align-items-center">..</div>
<div class="d-flex align-items-baseline">..</div>
<div class="d-flex
align-items-stretch">..</div>
Zarovnat se
Ovládejte vertikální zarovnání zadané flexibilní položky s .align-self-*
třídami. Platné třídy jsou .align-self-start
, .align-self-end
, .align-self-center
, .align-self-baseline
a .align-self-stretch
(výchozí).
Kliknutím na tlačítka níže zobrazíte rozdíl mezi těmito pěti třídami:
Příklad
Příklad
<div class="d-flex bg-light" style="height:150px">
<div
class="p-2 border">Flex item 1</div>
<div class="p-2 border
align-self-start">Flex item 2</div>
<div
class="p-2 border">Flex item 3</div>
</div>
Responzivní Flex třídy
All flex classes comes with additional responsive classes, which makes it easy to set a specific flex class on a specific screen size.
The *
symbol can be replaced with sm, md, lg or xl, which represents small, medium, large or xlarge screens.
Class | Description | Example |
---|---|---|
Flex Container | ||
.d-*-flex |
Creates a flexbox container for different screens | |
.d-*-inline-flex |
Creates an inline flexbox container for different screens | |
Direction | ||
.flex-*-row |
Display flex items horizontally on different screens | |
.flex-*-row-reverse |
Display flex items horizontally, and right-aligned, on different screens | |
.flex-*-column |
Display flex items vertically on different screens | |
.flex-*-column-reverse |
Display flex items vertically, with reversed order, on different screens screens | |
Justified Content | ||
.justify-content-*-start |
Display flex items from the start (left-aligned) on different screens | |
.justify-content-*-end |
Display flex items at the end (right-aligned) on different screens | |
.justify-content-*-center |
Display flex items in the center of a flex container on different screens | |
.justify-content-*-between |
Display flex items in "between" on different screens | |
.justify-content-*-around |
Display flex items "around" on different screens | |
Fill / Equal Width | ||
.flex-*-fill |
Force flex items into equal widths on different screens | |
Grow | ||
.flex-*-grow-0 |
Don't make the items grow on different screens | |
.flex-*-grow-1 |
Make items grow on different screens | |
Shrink | ||
.flex-*-shrink-0 |
Don't make the items shrink on diferent screens | |
.flex-*-shrink-1 |
Make items shrink on different screens | |
Order | ||
.order-*-0-12 |
Change the order from 0 to 12 on small screens | |
Wrap | ||
.flex-*-nowrap |
Don't wrap items on different screens | |
.flex-*-wrap |
Wrap items on different screens | |
.flex-*-wrap-reverse |
Reverse the wrapping of items on different screens | |
Align Content | ||
.align-content-*-start |
Align gathered items from the start on different screens | |
.align-content-*-end |
Align gathered items at the end on different screens | |
.align-content-*-center |
Align gathered items in the center on different screens | |
.align-content-*-around |
Align gathered items "around" on different screens | |
.align-content-*-stretch |
Stretch gathered items on different screens | |
Align Items | ||
.align-items-*-start |
Align single rows of items from the start on different screens | |
.align-items-*-end |
Align single rows of items at the end on different screens | |
.align-items-*-center |
Align single rows of items in the center on different screens | |
.align-items-*-baseline |
Align single rows of items on the baseline on different screens | |
.align-items-*-stretch |
Stretch single rows of items on different screens | |
Align Self | ||
.align-self-*-start |
Align a flex item from the start on different screens | |
.align-self-*-end |
Align a flex item at the end on different screens | |
.align-self-*-center |
Align a flex item in the center on different screens | |
.align-self-*-baseline |
Align a flex item on the baseline on different screens | |
.align-self-*-stretch |
Stretch a flex item on different screens |