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.
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 alinganayo. Isibonelo, izikhathi ezine.col-sm
ngayinye izoba ngu-25% ububanzi ngokuzenzakalelayo ukusuka endaweni encane yokuhlukana kuya phezulu. Bona isigaba samakholomu esakhiwo esizenzakalelayo ukuze uthole izibonelo ezengeziwe. - Amakilasi ekholomu abonisa inani lamakholomu ongathanda ukuwasebenzisa kwangenzeka kwayi-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, px
u-s usetshenziselwa 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 amadivaysi nendawo yokubuka, ukusuka xs
ku- xl
. Engeza noma iyiphi inombolo yamakilasi angenayunithi kuphoyinti ngalinye olidingayo futhi ikholomu ngayinye izoba nobubanzi obufanayo.
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.
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.
Sebenzisa col-{breakpoint}-auto
amakilasi usayizi wamakholomu ngokusekelwe kububanzi bemvelo bokuqukethwe kwawo.
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 .
Igridi ye-Bootstrap ihlanganisa izigaba ezinhlanu zamakilasi achazwe ngaphambilini okwakha izakhiwo ezisabelayo 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
.
Usebenzisa isethi eyodwa .col-sm-*
yamakilasi, ungakha isistimu yegridi eyisisekelo eqala isitakikhi bese iba evundlile endaweni encane yokuphumula ( sm
).
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.
Sebenzisa izinsiza zokuqondanisa kwe-flexbox ukuze uqondanise amakholomu aqondile naqondile.
Ama-gutter phakathi 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).
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.
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.
Ungase futhi usebenzise leli khefu ezindaweni ezithile zokunqamuka nezinsiza zethu zokubonisa ezisabelayo .
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.
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.
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.
Ngokungeziwe ekususeni ikholomu ezindaweni ezisabelayo, ungase udinge ukusetha kabusha ama-offset. Bona lokhu kusebenza esibonelweni segridi .
Ngokuthuthela ku-flexbox ku-v4, ungasebenzisa izinsiza zemajini njengokuphoqa amakholomu ezelamani ukuthi aqhelelane .mr-auto
.
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).
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 neziguquguqukayo 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.
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
isetha ububanzi bamagutha ekholomu.
Ukudlulela ngale kwamakholomu ngokwawo, ungase futhi wenze ngokwezifiso inani lezigaba 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 %
).