Isistimu yegridi
Sebenzisa igridi yethu ye-flexbox ye-mobile-first flexbox enamandla ukuze wakhe izakhiwo zabo bonke umumo nosayizi ngenxa yesistimu yamakholomu ayishumi nambili, izigaba ezinhlanu ezisabelayo ezizenzakalelayo, okuguquguqukayo kwe-Sass nezingxube, kanye nenqwaba yamakilasi achazwe ngaphambilini.
Isistimu yegridi ye-Bootstrap isebenzisa uchungechunge lweziqukathi, imigqa, namakholomu ukuze kuhlelwe futhi kuqondiswe okuqukethwe. Yakhiwe nge- flexbox futhi isabela ngokugcwele. Ngezansi kunesibonelo kanye nokubheka okujulile kokuthi igridi ihlangana kanjani.
Umusha noma awujwayele nge-flexbox? Funda lo mhlahlandlela webhokisi le-CSS Tricks ukuze uthole ingemuva, amagama, imihlahlandlela, namazwibela ekhodi.
<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>
Isibonelo esingenhla sidala amakholomu amathathu anobubanzi obulinganayo kumadivayisi amancane, amaphakathi, amakhulu, namakhulu ngokwengeziwe sisebenzisa amakilasi ethu egridi achazwe kusengaphambili. Lawo makholomu agxile ekhasini elinomzali .container
.
Ukuyihlukanisa, nansi indlela esebenza ngayo:
- Iziqukathi zinikeza indlela yokubeka phakathi nendawo nokupheda okuqukethwe kwesayithi lakho. Sebenzisa
.container
kububanzi bephikseli esabelayo noma.container-fluid
kuzowidth: 100%
zonke izimbobo zokubuka nosayizi bedivayisi. - Imigqa iwukugoqa kwamakholomu. Ikholomu ngayinye inezingqimba
padding
(okuthiwa i-gutter) yokulawula isikhala phakathi kwazo. Lokhupadding
kube sekuphikiswa emigqeni enemajini eyinegethivu. Ngale ndlela, konke okuqukethwe kumakholomu akho kuqondaniswe ngokubonakalayo phansi kwesokunxele. - Kusakhiwo segridi, okuqukethwe kufanele kufakwe phakathi kwamakholomu futhi amakholomu kuphela angaba izingane zemigqa.
- Ngenxa ye-flexbox, amakholomu egridi ngaphandle kokucaciswa azohleleka
width
ngokuzenzakalelayo njengamakholomu obubanzi obulinganayo. Isibonelo, izikhathi ezine.col-sm
ngayinye izoba ngu-25% ububanzi ngokuzenzakalelayo ukusuka endaweni encane yokuhlukana nokukhuphuka. Bona isigaba samakholomu esakhiwo esizenzakalelayo ukuze uthole izibonelo ezengeziwe. - Amakilasi ekholomu abonisa inani lamakholomu ongathanda ukuwasebenzisa kwanokuba ngu-12 umugqa ngamunye. Ngakho-ke, uma ufuna amakholomu amathathu anobubanzi obulinganayo ngaphesheya, ungasebenzisa
.col-4
. - Amakholomu
width
s asethwe ngamaphesenti, ngakho ahlala ewuketshezi futhi enosayizi ngokuhlobene nento yawo engumzali. - Amakholomu anezingqimba ukuze enze ama
padding
-gutters phakathi kwamakholomu angawodwana, nokho-ke, ungakwazi ukususamargin
emigqenipadding
nakumakholomu nge- ..no-gutters
.row
- Ukuze wenze igridi iphendule, kunezindawo zokunqamuka zegridi ezinhlanu, eyodwa endaweni ngayinye esabelayo yokuphumula : wonke ama-breakpoint (amancane kakhulu), amancane, amaphakathi, amakhulu, kanye namakhulu kakhulu.
- Ama-breakpoints egridi asekelwe kumibuzo yemidiya yobubanzi obuncane, okusho ukuthi asebenza kuleyo ndawo eyodwa yokunqamuka kanye nabo bonke abangaphezulu kwayo (isb.,
.col-sm-4
kusebenza kumadivayisi amancane, amaphakathi, amakhulu, namakhulu kakhulu, kodwa hhayi indawo yokuqalaxs
yokunqamuka). - Ungasebenzisa amakilasi egridi achazwe ngaphambilini (njenge
.col-4
) noma imiksi ye- Sass ukuze uthole umaki we-semantic owengeziwe.
Qaphela imikhawulo neziphazamisi ezizungeze i-flexbox , njengokungakwazi ukusebenzisa ezinye izici ze-HTML njengeziqukathi eziguquguqukayo .
Ngenkathi i-Bootstrap isebenzisa u em
-s noma rem
u-s ukuchaza osayizi abaningi, o px
-s basetshenziselwa ukunqanyulwa kwegridi nobubanzi besiqukathi. Lokhu kungenxa yokuthi ububanzi bembobo yokubuka bungamaphikseli futhi abushintshi nosayizi wefonti .
Bona ukuthi izici zesistimu yegridi ye-Bootstrap zisebenza kanjani kuwo wonke amadivayisi anetafula eliwusizo.
Okuncane kakhulu < 576px |
Okuncane ≥576px |
Okumaphakathi ≥768px |
Okukhulu ≥992px |
Okukhulu kakhulu ≥1200px |
|
---|---|---|---|---|---|
Ububanzi besiqukathi esikhulu | Lutho (okuzenzakalelayo) | 540px | 720px | 960px | 1140px |
Isiqalo sekilasi | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
# wamakholomu | 12 | ||||
Ububanzi be-Gutter | 30px (15px ohlangothini ngalunye lwekholomu) | ||||
I-Nestable | Yebo | ||||
Ukuhleleka kwekholomu | Yebo |
Sebenzisa amakilasi ekholomu aqondene ne-breakpoint ukuze kube lula ukulinganisa ikholomu ngaphandle kwekilasi elinezinombolo ezicacile njenge- .col-sm-6
.
Isibonelo, nazi izakhiwo zegridi ezimbili ezisebenza kuwo wonke amadivayisi nembobo yokubuka, ukusuka xs
ku- xl
. Engeza noma iyiphi inombolo yamakilasi angenayunithi kuphoyinti ngalinye olidingayo futhi ikholomu ngayinye izoba nobubanzi obufanayo.
<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>
Amakholomu anobubanzi obulinganayo angahlukaniswa abe imigqa eminingi, kodwa kube nesiphazamisi se- Safari flexbox esivimbe lokhu ekusebenzeni ngaphandle kokubeka obala flex-basis
noma border
. Kunezinhlelo zokusebenza zezinguqulo zesiphequluli ezindala, kodwa akufanele zidingeke uma unolwazi lwakamuva.
<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>
Isakhiwo esizenzakalelayo samakholomu egridi ye-flexbox siphinde sisho ukuthi ungasetha ububanzi bekholomu eyodwa futhi ube namakholomu ayizelamani ashintsha usayizi ngokuzenzakalelayo kuwo. Ungasebenzisa amakilasi egridi achazwe ngaphambilini (njengoba kukhonjisiwe ngezansi), imiksi yegridi, noma ububanzi bomugqa. Qaphela ukuthi amanye amakholomu azoshintsha usayizi kungakhathaliseki ububanzi bekholomu emaphakathi.
<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>
Sebenzisa col-{breakpoint}-auto
amakilasi usayizi wamakholomu ngokusekelwe kububanzi bemvelo bokuqukethwe kwawo.
<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>
Dala amakholomu anobubanzi obulinganayo anwebeka imigqa eminingi ngokufaka .w-100
lapho ofuna ukuthi amakholomu aqhekeze khona emugqeni omusha. Yenza amakhefu aphendule ngokuxuba .w-100
izinsiza zokubonisa ezisabelayo .
<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>
Igridi ye-Bootstrap ihlanganisa izigaba ezinhlanu zamakilasi achazwe ngaphambilini okwakha izakhiwo eziphendulayo eziyinkimbinkimbi. Enza ngendlela oyifisayo usayizi wamakholomu akho kumadivayisi amancane, amancane, amaphakathi, amakhulu, noma amakhulu ngokwengeziwe ngendlela obona kufaneleke ngayo.
Kumagridi afanayo kusukela kwamadivayisi amancane kakhulu ukuya kwamakhulu, sebenzisa i- .col
kanye .col-*
namakilasi. Cacisa ikilasi elinezinombolo uma udinga ikholomu enosayizi othile; ngaphandle kwalokho, zizwe ukhululekile ukunamathela .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>
Usebenzisa isethi eyodwa .col-sm-*
yamakilasi, ungakha isistimu yegridi eyisisekelo eqala isitakikhi ngaphambi kokuba ivundlile endaweni encane yokuphumula ( 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>
Awufuni ukuthi amakholomu akho avele anqwabelene kwezinye izigaba zegridi? Sebenzisa inhlanganisela yamakilasi ahlukene esigabeni ngasinye njengoba kudingeka. Bheka isibonelo esingezansi ukuze uthole umbono ongcono wokuthi konke kusebenza kanjani.
<!-- 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>
Sebenzisa izinsiza zokuqondanisa kwe-flexbox ukuze uqondanise amakholomu aqondile futhi avundlile.
<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>
Ama-gutters aphakathi kwamakholomu kumakilasi ethu egridi achazwe kusengaphambili angasuswa ngokuthi .no-gutters
. Lokhu kususa okuthi-negethivu u- margin
s kusuka .row
kanye nokuvundlile padding
kuwo wonke amakholomu ezingane.
Nansi ikhodi yomthombo yokudala lezi zitayela. Qaphela ukuthi ukukhishwa kwekholomu kuhanjiswa kumakholomu okuqala kuphela ezingane futhi kuqondiswe kusikhethi sesibaluli . Nakuba lokhu kukhiqiza isikhethi esiqondile, ukupheda kwekholomu kusengabuye kwenziwe ngendlela oyifisayo ngezinsiza zokuhlukanisa isikhala .
Udinga idizayini esukela konqenqemeni ukuya konqenqemeni? Lahla umzali .container
noma .container-fluid
.
Ngokusebenza, nansi indlela ebukeka ngayo. Qaphela ukuthi ungaqhubeka nokusebenzisa lokhu nawo wonke amanye amakilasi egridi achazwe ngaphambilini (okuhlanganisa ububanzi bekholomu, izigaba ezisabelayo, ukuhlela kabusha, nokuningi).
<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>
Uma amakholomu angaphezu kuka-12 ebekwe phakathi komugqa owodwa, iqembu ngalinye lamakholomu engeziwe, njengeyunithi eyodwa, lizogoqa emugqeni omusha.
Kusukela ku-9 + 4 = 13 > 12, le div enamakholomu angu-4 ebanzi igoqwa emugqeni omusha njengeyunithi eyodwa ehlangene.
Amakholomu alandelayo ayaqhubeka emugqeni omusha.
<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>
Ukuhlephula amakholomu emugqeni omusha ku-flexbox kudinga ukugenca okuncane: engeza i-elementi nanoma width: 100%
yikuphi lapho ufuna ukugoqa khona amakholomu akho emugqeni omusha. Imvamisa lokhu kufezwa ngama-multiple .row
s, kodwa akuzona zonke izindlela zokuqalisa ezingamela lokhu.
<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>
Ungase futhi usebenzise leli khefu ezindaweni ezithile zokunqamuka nezinsiza zethu zokubonisa ezisabelayo .
<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>
Sebenzisa .order-
amakilasi ukuze ulawule ukuhleleka okubukwayo kokuqukethwe kwakho. Lawa makilasi ayasabela, ngakho-ke ungasetha i- order
breakpoint (isb, .order-1.order-md-2
). Kufaka phakathi ukwesekwa 1
kuzo 12
zonke izigaba ezinhlanu zamagridi.
<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>
Kukhona futhi amakilasi aphendulayo .order-first
namakilasi .order-last
ashintsha order
isici ngokufaka order: -1
kanye order: 13
( order: $columns + 1
), ngokulandelanayo. Lawa makilasi angabuye axutshwe .order-*
namakilasi anezinombolo njengoba kudingeka.
<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>
Ungakwazi ukulungisa amakholomu egridi ngezindlela ezimbili: .offset-
amakilasi ethu egridi aphendulayo kanye nezinsiza zethu zemajini . Amakilasi egridi alinganiswa ukuze afane namakholomu kuyilapho amamajini ewusizo kakhulu ezakhiweni ezisheshayo lapho ububanzi be-offset buyahlukahluka.
Hambisa amakholomu kwesokudla usebenzisa .offset-md-*
amakilasi. Lezi zigaba zandisa umkhawulo wesokunxele wekholomu *
ngamakholomu. Isibonelo, .offset-md-4
ihamba .col-md-4
phezu kwamakholomu amane.
<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>
Ngokungeziwe ekususeni ikholomu ezindaweni ezisabelayo, ungase udinge ukusetha kabusha ama-offset. Bona lokhu kusebenza esibonelweni segridi .
<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>
Ngokuthuthela ku-flexbox ku-v4, ungasebenzisa izinsiza zemajini njengokuphoqa amakholomu ezelamani ukuthi aqhelelane .mr-auto
.
<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>
Ukuze uhlanganise okuqukethwe kwakho ngegridi ezenzakalelayo, engeza entsha .row
nesethi .col-sm-*
yamakholomu ngaphakathi kwekholomu ekhona .col-sm-*
. Imigqa efakwe kusidleke kufanele ifake isethi yamakholomu ahlanganisa kufika ku-12 noma ngaphansi (akudingekile ukuthi usebenzise wonke amakholomu angu-12 atholakalayo).
<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>
Uma usebenzisa amafayela we-Sass womthombo we-Bootstrap, unenketho yokusebenzisa okuguquguqukayo kwe-Sass nezingxube ukuze udale ukwakheka kwekhasi langokwezifiso, le-semantic, kanye nekhasi eliphendulayo. Amakilasi ethu egridi achazwe ngaphambilini asebenzisa lezi zimo eziguquguqukayo nezixube ukuhlinzeka ngesudi ephelele yamakilasi alungele ukusetshenziswa ezakhiwo ezisabelayo ngokushesha.
Okuguquguqukayo namamephu kunquma inani lamakholomu, ububanzi be-gutter, kanye nendawo yombuzo wemidiya okufanele kuqalwe kuyo amakholomu antantayo. Sisebenzisa lezi ukuze sikhiqize amakilasi egridi achazwe ngaphambilini abhalwe ngenhla, kanye nezingxube zangokwezifiso ezibalwe ngezansi.
Imiksi isetshenziswa ngokuhambisana neziguquko zegridi ukuze kukhiqizwe i-CSS ye-semantic yamakholomu egridi ngayinye.
Ungakwazi ukuguqula okuguquguqukayo kube ngamavelu akho angokwezifiso, noma usebenzise nje ama-mixins ngamavelu awo azenzakalelayo. Nasi isibonelo sokusebenzisa izilungiselelo ezizenzakalelayo ukuze udale isakhiwo samakholomu amabili esinegebe phakathi.
<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>
Ngokusebenzisa okuguquguqukayo kwegridi ye-Sass eyakhelwe ngaphakathi namamephu, kungenzeka ukwenza ngendlela oyifisayo amakilasi egridi achazwe ngaphambilini. Shintsha inani lama-tiers, ubukhulu bemibuzo yemidiya, nobubanzi besiqukathi—bese uhlanganisa futhi.
Inani lamakholomu egridi lingashintshwa ngokusebenzisa okuguquguqukayo kwe-Sass. $grid-columns
isetshenziselwa ukukhiqiza ububanzi (ngamaphesenti) bekholomu ngayinye kuyilapho $grid-gutter-width
ivumela ububanzi obuqondile be-breakpoint obuhlukaniswa ngokulinganayo phakathi padding-left
nakumagatha padding-right
ekholomu.
Ukudlulela ngale kwamakholomu ngokwawo, ungase futhi wenze ngendlela oyifisayo inombolo yezigaba zegridi. Uma ubufuna amagridi amane kuphela, ungabuyekeza $grid-breakpoints
futhi $container-max-widths
kube into efana nalena:
Uma wenza noma yiziphi izinguquko eziguquguqukayo ze-Sass noma amamephu, uzodinga ukuthi ulondoloze izinguquko zakho futhi uphinde uhlanganise. Ukwenza kanjalo kuzokhipha isethi entsha sha yamakilasi egridi achazwe kusengaphambili obubanzi bekholomu, ama-offset, noku-oda. Izinsiza ezibonakalayo ezisabelayo nazo zizobuyekezwa ukuze kusetshenziswe ama-breakpoints angokwezifiso. Qiniseka ukuthi usetha amanani egridi ku px
(hhayi rem
, em
, noma %
).