Système ya grille
Salelá grille na biso ya nguya ya mobile-first flexbox mpo na kotonga ba layouts ya ba shapes mpe bonene nyonso grâce na système ya ba colonnes zomi na mibale, ba niveaux mitano ya réponse par défaut, ba variables ya Sass mpe ba mixins, mpe ba douzaines ya ba classes oyo esili ko définir.
Système ya grille ya Bootstrap esalelaka série ya ba conteneurs, ba lignes, na ba colonnes pona ko layout pe ko aligner contenus. Etongami na flexbox mpe ezali na boyokani mobimba. Awa na nse ezali na ndakisa mpe botali na bozindo lolenge nini grille esanganaka.
Ozali ya sika to oyebi te flexbox? Tanga buku oyo ya flexbox ya CSS Tricks mpo na koyeba makambo ya nsima, maloba, malako, mpe biteni ya code.
<div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div>
Ndakisa oyo ezali likolo esali ba colonnes misato ya bonene ekokani na ba dispositifs ya mike, ya monene, ya minene, mpe ya minene mingi koleka na kosalelaka ba classes na biso ya grille oyo esili kolimbolama liboso. Makonzí yango ezali na katikati ya lokasa oyo ezali na moboti .container
.
Kobuka yango, tala ndenge esalaka:
- Ba conteneurs epesaka moyen ya ko centrer pe ko pad horizontalement ba contenus ya site na yo. Salelá
.container
mpo na bonene ya pixel oyo ezali koyanola to.container-fluid
mpo na nawidth: 100%
kati ya bonene nyonso ya esika ya kotala mpe ya aparɛyi. - Milɔngɔ́ ezali ba enveloppes mpo na makonzí. Kolona mokomoko ezali na horizontal
padding
(oyo babengaka gouttière) mpo na kotambwisa esika oyo ezali kati na yango. Napadding
nsima, bazongisaka yango na milɔngɔ oyo ezali na ba marges négatifs. Na ndenge yango, makambo nyonso oyo ezali na makonzí na yo ezali na molɔngɔ na miso na nse na ngámbo ya lobɔkɔ ya mwasi. - Na bobongisi ya grille, esengeli kotia makambo na kati ya makonzí mpe kaka makonzí ekoki kozala bana ya mbala moko ya milɔngɔ.
- Grâce na flexbox, ba colonnes ya grille sans un précisé
width
eko layout automatiquement lokola ba colonnes ya largeur égale. Ndakisa, ba instances minei ya.col-sm
ekozala automatiquement 25% ya largeur kobanda na point de rupture ya moke mpe likolo. Tala eteni ya ba colonnes auto-layout mpo na bandakisa mosusu. - Ba kelasi ya makonzí emonisaka motángo ya makonzí oyo olingi kosalela na kati ya 12 oyo ekoki kozala na molɔngɔ moko. Na yango, soki olingi makonzí misato ya bonene ekokani na ngámbo mosusu, okoki kosalela
.col-4
. - Ba colonnes
width
s etiamaki na ba pourcentages, yango wana ezalaka toujours fluide mpe na taille par rapport na élément parent na yango. - Makonzí ezali na horizontal
padding
mpo na kosala ba gouttières kati na makonzí mokomoko, nzokande, okoki kolongola oyomargin
euti na milɔngɔ mpepadding
na makonzí na.no-gutters
likoló ya.row
. - Mpo na kosala ete grille ezala na eyano, ezali na ba points de rupture ya grille mitano, moko mpo na point de rupture moko na moko oyo ezo répondre : ba points de rupture nionso (extra petit), ya mike, ya monene, ya monene, mpe ya monene mingi.
- Ba points de rupture ya grille esalemi na ba requêtes ya media ya largeur minimum, elingi koloba esalemaka na point de rupture moko wana mpe nionso oyo ezali likolo na yango (ndakisa,
.col-sm-4
etali ba dispositifs ya mike, ya moyenne, ya minene, mpe ya monene mingi, kasi point yaxs
rupture ya liboso te). - Okoki kosalela ba classes ya grille oyo e définir liboso (lokola
.col-4
) to ba mixins ya Sass pona marquage sémantique mingi.
Yeba ba limitations na ba bugs zinga zinga ya flexbox , lokola incapacité ya kosalela ba éléments HTML misusu lokola ba conteneurs flex .
Atako Bootstrap esalela em
s to rem
s mpo na kolimbola bonene mingi, px
s esalelamaka mpo na ba points de rupture ya grille mpe bonene ya ba conteneurs. Yango ezali mpo ete bonene ya esika ya kotala ezali na ba pixels mpe ebongwanaka te na bonene ya makomi .
Tala ndenge nini makambo ya système ya grille ya Bootstrap esalaka na kati ya ba dispositifs ebele na tableau ya maboko.
Extra ya moke <576px |
Moke ≥576px |
Moyenne ≥768px |
Monene ≥992px |
Extra ya monene ≥1200px |
|
---|---|---|---|---|---|
Max largeur ya récipient | Moko te (auto) . | 540px na yango | 720px ezali | 960px ezali | 1140px na yango |
Prefixe ya kelasi | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
# ya makonzí | 12 | ||||
Largeur ya gouttière | 30px (15px na ngambo moko na moko ya colonne) | ||||
Esika ya kofanda | Iyo | ||||
Kosala komande ya makonzí | Iyo |
Salelá bakelasi ya makonzí oyo etali esika ya kobuka mpo na kosala bonene ya makonzí na pɛtɛɛ nyonso kozanga kelasi oyo ezali na nimero ya polele lokola .col-sm-6
.
Ndakisa, awa ezali na ba layouts mibale ya grille oyo etali appareil nionso mpe na esika ya kotala, kobanda xs
na xl
. Bakisa nombre nionso ya ba classes sans unité pona point de rupture moko na moko oyo esengeli pe colonne nionso ekozala na largeur moko.
<div class="container">
<div class="row">
<div class="col">
1 of 2
</div>
<div class="col">
2 of 2
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col">
2 of 3
</div>
<div class="col">
3 of 3
</div>
</div>
</div>
Ba colonnes ya largeur ekokani ekoki kobukana na ba lignes ebele, kasi ezalaki na bug ya flexbox ya Safari oyo epekisaki oyo esala sans explicit flex-basis
to border
. Ezali na ba solutions mpo na ba versions ya kala ya navigateur, kasi esengeli te kozala na ntina soki ozali na mikolo.
<div class="container">
<div class="row">
<div class="col">Column</div>
<div class="col">Column</div>
<div class="w-100"></div>
<div class="col">Column</div>
<div class="col">Column</div>
</div>
</div>
Auto-layout mpo na makonzí ya grille flexbox elakisi mpe ete okoki kotya bonene ya colonne moko mpe kosala ete makonzí ya bandeko ebongola bonene na yango automatique zingazinga na yango. Okoki kosalela ba classes ya grille oyo esili kolimbolama liboso (lokola elakisami awa na se), ba mixins ya grille, to ba largeurs ya kati ya ligne. Yebá ete makonzí mosusu ekobongola bonene ata soki makonzí ya katikati ezali na bonene boni.
<div class="container">
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-6">
2 of 3 (wider)
</div>
<div class="col">
3 of 3
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-5">
2 of 3 (wider)
</div>
<div class="col">
3 of 3
</div>
</div>
</div>
Salelá col-{breakpoint}-auto
bakelasi mpo na kopesa bonene ya makonzí na kotalela bonene ya bomoto ya makambo oyo ezali na kati na yango.
<div class="container">
<div class="row justify-content-md-center">
<div class="col col-lg-2">
1 of 3
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
<div class="row">
<div class="col">
1 of 3
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
</div>
Salá makonzí ya bonene ekokani oyo ezali na milɔngɔ mingi na kokɔtisáká .w-100
esika oyo olingi makonzí ekabwana na molɔngɔ ya sika. Salá ete ba pauses ezala na boyokani na kosangisáká .w-100
na mwa ba utilitaires ya kolakisa oyo ezali koyanola .
<div class="row">
<div class="col">col</div>
<div class="col">col</div>
<div class="w-100"></div>
<div class="col">col</div>
<div class="col">col</div>
</div>
Grille ya Bootstrap ezali na ba niveaux mitano ya ba classes prédéfinies mpo na kotonga ba layouts complexes oyo ezo répondre. Personnaliser taille ya ba colonnes na yo na ba appareils ya mike mingi, ya mike, ya moyenne, ya minene, to ya minene mingi ndenge nini omoni malamu.
Mpo na ba grille oyo ezali ndenge moko kobanda na ba dispositif ya moke tii na oyo ya monene, salelá ba classes .col
mpe . .col-*
Lakisa kelasi oyo ezali na banimero ntango ozali na mposa ya likonzi oyo ezali na bonene mpenza; soki te, yoká nsɔni te ya kokangama na .col
.
<div class="row">
<div class="col">col</div>
<div class="col">col</div>
<div class="col">col</div>
<div class="col">col</div>
</div>
<div class="row">
<div class="col-8">col-8</div>
<div class="col-4">col-4</div>
</div>
Na kosalelaka ensemble moko ya ba .col-sm-*
classes, okoki kosala système ya grille ya base oyo ebandi stacked avant ekoma horizontal na na point de rupture ya moke ( sm
).
<div class="row">
<div class="col-sm-8">col-sm-8</div>
<div class="col-sm-4">col-sm-4</div>
</div>
<div class="row">
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
</div>
Olingi te ba colonnes na yo ezala kaka ebele na ba niveaux ya grille mosusu? Salelá kosangisa bakelasi ndenge na ndenge mpo na nivo mokomoko soki esengeli. Tala ndakisa oyo ezali awa na nse mpo na koyeba malamu ndenge oyo nyonso esalaka.
<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="row">
<div class="col-12 col-md-8">.col-12 .col-md-8</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
<div class="row">
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
<!-- Columns are always 50% wide, on mobile and desktop -->
<div class="row">
<div class="col-6">.col-6</div>
<div class="col-6">.col-6</div>
</div>
Salelá ba utilitaires ya alignment ya flexbox mpo na ko aligner ba colonnes verticalement mpe horizontalement.
<div class="container">
<div class="row align-items-start">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<div class="row align-items-center">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<div class="row align-items-end">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col align-self-start">
One of three columns
</div>
<div class="col align-self-center">
One of three columns
</div>
<div class="col align-self-end">
One of three columns
</div>
</div>
</div>
<div class="container">
<div class="row justify-content-start">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-center">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-end">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-around">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
<div class="row justify-content-between">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
</div>
Ba gouttières entre ba colonnes na ba classes na biso ya grille pré-définies ekoki ko longwa na .no-gutters
. Yango elongolaka margin
s négatif na .row
mpe horizontal padding
na ba colonnes nionso ya bana ya mbala moko.
Tala code source pona kosala ba styles oyo. Yeba ete ba overrides ya colonne ezali scoped kaka na ba colonnes ya bana ya liboso mpe ezali ciblé na nzela ya selecteur ya attribut . Atako yango ebimisaka moponi moko ya sikisiki mingi, remplissage ya makonzí ekoki kaka kozala personnalisé lisusu na ba utilitaires ya espacement .
Ozali na mposa ya design ya bord-à-edge? Bwaka moboti .container
to .container-fluid
.
Na pratique, tala ndenge ezo monana. Liyebisi okoki kokoba kosalela oyo na bakelasi mosusu nyonso ya grille oyo esili kolimbolama liboso (elongo na bonene ya makonzí, ba niveaux ya eyano, ba réordonnées, mpe mingi mosusu).
<div class="row no-gutters">
<div class="col-12 col-sm-6 col-md-8">.col-12 .col-sm-6 .col-md-8</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
Soki batye makonzí koleka 12 na kati ya molɔngɔ moko, etuluku mokomoko ya makonzí mosusu ekozipama, lokola unité moko, na molɔngɔ ya sika.
Lokola 9 + 4 = 13 > 12, div oyo ya 4 colonne-largeur ezuaka enveloppé na ligne ya sika lokola unité moko contigue.
Makonzí oyo elandi ezali kokoba na nzela ya molɔngɔ ya sika.
<div class="row">
<div class="col-9">.col-9</div>
<div class="col-4">.col-4<br>Since 9 + 4 = 13 > 12, this 4-column-wide div gets wrapped onto a new line as one contiguous unit.</div>
<div class="col-6">.col-6<br>Subsequent columns continue along the new line.</div>
</div>
Kobuka ba colonnes na ligne ya sika na flexbox esengaka petit hack : bakisa élément na width: 100%
esika nionso olingi ko envelopper ba colonnes na yo na ligne ya sika. Normalement yango ekokisama na ba .row
s ebele, kasi te méthode nionso ya mise en œuvre ekoki ko comptabiliser yango.
<div class="row">
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<!-- Force next columns to break to new line -->
<div class="w-100"></div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
<div class="col-6 col-sm-3">.col-6 .col-sm-3</div>
</div>
Okoki mpe kosalela pause oyo na ba points spécifiques ya rupture na ba utilitaires na biso ya écran oyo ezo répondre .
<div class="row">
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<!-- Force next columns to break to new line at md breakpoint and up -->
<div class="w-100 d-none d-md-block"></div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
<div class="col-6 col-sm-4">.col-6 .col-sm-4</div>
</div>
Salelá .order-
bakelasi mpo na kotambwisa molongo ya komona ya makambo na yo. Ba classes oyo ezali responsive, yango wana okoki ko setting the order
by breakpoint (par exemple, .order-1.order-md-2
). Esangisi lisungi mpo 1
na nzela 12
na kati ya ba niveaux nionso mitano ya grille.
<div class="container">
<div class="row">
<div class="col">
First, but unordered
</div>
<div class="col order-12">
Second, but last
</div>
<div class="col order-1">
Third, but first
</div>
</div>
</div>
Ezali mpe na ba classes responsives .order-first
mpe .order-last
oyo ebongoli ya order
ya élément moko na kosalelaka order: -1
mpe order: 13
( order: $columns + 1
), respectivement. Bakelasi yango ekoki mpe kosangisama na .order-*
bakelasi oyo ezali na banimero soki esengeli.
<div class="container">
<div class="row">
<div class="col order-last">
First, but last
</div>
<div class="col">
Second, but unordered
</div>
<div class="col order-first">
Third, but first
</div>
</div>
</div>
Okoki ko offset ba colonnes ya grille na ndenge mibale: .offset-
ba classes na biso ya grille oyo ezo répondre na ba utilitaires na biso ya marge . Ba classes ya grille ezali na taille mpo na ko correspondre na ba colonnes pendant que ba marges ezali na tina mingi pona ba layouts ya mbangu esika largeur ya offset ezali variable.
Bokende na makonzí na lobɔkɔ ya mobali na kosaleláká .offset-md-*
bakelasi. Bakelasi yango ebakisaka marge ya lobɔkɔ ya mwasi ya likoló na *
makonzí. Na ndakisa, .offset-md-4
etambolaka .col-md-4
likoló ya makonzí minei.
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div>
</div>
<div class="row">
<div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
<div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
</div>
<div class="row">
<div class="col-md-6 offset-md-3">.col-md-6 .offset-md-3</div>
</div>
Longola bolongolami ya makonzí na bisika ya kobuka oyo eyanolaka, ekoki kozala ete osengeli kozongisa ba offsets na esika na yango. Tala yango na misala na ndakisa ya grille .
<div class="row">
<div class="col-sm-5 col-md-6">.col-sm-5 .col-md-6</div>
<div class="col-sm-5 offset-sm-2 col-md-6 offset-md-0">.col-sm-5 .offset-sm-2 .col-md-6 .offset-md-0</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-5 col-lg-6">.col-sm-6 .col-md-5 .col-lg-6</div>
<div class="col-sm-6 col-md-5 offset-md-2 col-lg-6 offset-lg-0">.col-sm-6 .col-md-5 .offset-md-2 .col-lg-6 .offset-lg-0</div>
</div>
Na kokende na flexbox na v4, okoki kosalela ba utilitaires ya marge lokola .mr-auto
ko forcer ba colonnes ya bandeko mosika moko na mosusu.
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 ml-auto">.col-md-4 .ml-auto</div>
</div>
<div class="row">
<div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>
<div class="col-md-3 ml-md-auto">.col-md-3 .ml-md-auto</div>
</div>
<div class="row">
<div class="col-auto mr-auto">.col-auto .mr-auto</div>
<div class="col-auto">.col-auto</div>
</div>
Mpo na kosala nest ya makambo na yo na grille ya liboso, bakisa ya sika .row
mpe ensemble ya .col-sm-*
ba colonnes na kati ya .col-sm-*
colonne oyo ezali. Milɔngɔ́ oyo ekangami esengeli kozala na ensemble ya makonzí oyo ebakisami kino na 12 to na nse (esengeli te osalela makonzí nyonso 12 oyo ezali).
<div class="row">
<div class="col-sm-9">
Level 1: .col-sm-9
<div class="row">
<div class="col-8 col-sm-6">
Level 2: .col-8 .col-sm-6
</div>
<div class="col-4 col-sm-6">
Level 2: .col-4 .col-sm-6
</div>
</div>
</div>
</div>
Ntango ozali kosalela ba fichiers Sass ya source ya Bootstrap, ozali na option ya kosalela ba variables ya Sass mpe ba mixins mpo na kosala ba layouts ya page personnalisé, sémantique, mpe responsive. Ba classes na biso ya grille prédéfinies esalela ba variables na ba mixins oyo moko pona kopesa suite mobimba ya ba classes prêtes à utiliser pona ba layouts oyo ezo répondre rapide.
Ba variables mpe ba cartes elakisaka motango ya ba colonnes, largeur ya gouttière, mpe point ya requête ya media oyo esengeli kobanda ba colonnes flottantes. Tosalelaka oyo mpo na kobimisa ba classes ya grille oyo esili kolimbolama liboso oyo ekomami likolo, mpe lisusu mpo na ba mixins personnalisés oyo etangami awa na se.
Ba mixins esalelamaka elongo na ba variables ya grille pona kobimisa CSS sémantique pona ba colonne ya grille moko moko.
Okoki ko modifier ba variables na ba valeurs personnalisées na yo moko, to kosalela kaka ba mixins na ba valeurs na bango ya par défaut. Tala ndakisa ya kosalela ba paramètres ya liboso mpo na kosala layout ya makonzí mibale na esika oyo ezali kati na yango.
<div class="example-container">
<div class="example-row">
<div class="example-content-main">Main content</div>
<div class="example-content-secondary">Secondary content</div>
</div>
</div>
Na kosalelaka ba variables na biso ya grille Sass oyo etongami na kati mpe ba cartes, ezali possible ya ko personnaliser entièrement ba classes ya grille prédéfinies. Bobongola motango ya ba niveaux, ba dimensions ya requête ya media, mpe ba largeurs ya conteneur —na sima recompiler.
Motango ya ba colonne ya grille ekoki kobongisama na nzela ya ba variables ya Sass. $grid-columns
esalelami mpo na kobimisa bonene (na mokama) ya makonzí moko na moko wana $grid-gutter-width
epesaka nzela na bonene ya esika ya kobuka oyo ekabolami ndenge moko na kati padding-left
mpe padding-right
mpo na ba gouttières ya makonzí.
Koleka ba colonnes yango moko, okoki pe ko personnaliser nombre ya ba niveaux ya grille. Soki olingaki kaka ba niveaux minei ya grille, olingaki kosala mise à jour ya $grid-breakpoints
mpe $container-max-widths
na eloko lokola oyo:
Ntango ozali kosala mbongwana nyonso na ba variables to ba cartes ya Sass, ekosenga obomba mbongwana na yo mpe o recompiler. Kosala bongo ekobimisa ensemble ya sika mpenza ya ba classes ya grille oyo esili kolimbolama liboso mpo na bonene ya makonzí, ba offsets, mpe kosala komande. Ba utilitaires ya visibilité oyo ezo répondre ekozala pe mise à jour pona kosalela ba points de rupture personnalisé. Sala makasi otia ba valeurs ya grille na px
(te rem
, em
, to %
).