Igridi ye-CSS
Funda ukuthi uvumela kanjani, usebenzise, futhi wenze ngendlela oyifisayo enye isistimu yethu yesakhiwo eyakhelwe ku-CSS Grid enezibonelo namazwibela ekhodi.
Isistimu yegridi ezenzakalelayo ye-Bootstrap imele isiphetho seminyaka engaphezu kweshumi yamasu wesakhiwo se-CSS, azanywe futhi avivinywa izigidi zabantu. Kodwa, iphinde yadalwa ngaphandle kwezici eziningi zesimanje ze-CSS namasu esiwabona kuziphequluli ezifana ne-CSS Grid entsha.
Isebenza kanjani
Nge-Bootstrap 5, sengeze inketho yokunika amandla isistimu yegridi ehlukile eyakhelwe ku-CSS Grid, kodwa nge-Bootstrap twist. Usawathola amakilasi ongawafaka ngokuthanda kwakho ukuze wakhe izakhiwo ezisabelayo, kodwa ngendlela ehlukile ngaphansi kwe-hood.
-
Igridi ye-CSS ikhethe ukungena. Khubaza isistimu yegridi emisiwe ngokusetha
$enable-grid-classes: false
futhi unike amandla Igridi ye-CSS ngokusetha$enable-cssgrid: true
. Bese, hlanganisa kabusha i-Sass yakho. -
Faka esikhundleni izibonelo
.row
nge.grid
. Ikilasi.grid
lisethadisplay: grid
futhi lidalegrid-template
owakha phezu kwalo nge-HTML yakho. -
Shintshanisa
.col-*
amakilasi.g-col-*
ngamakilasi. Lokhu kungenxa yokuthi amakholomu ethu eGridi ye-CSS asebenzisagrid-column
isakhiwo esikhundleni se-width
. -
Amakholomu nosayizi we-gutter asethwa ngokuguquguquka kwe-CSS. Zibeke kumzali
.grid
futhi wenze ngendlela othanda ngayo noma kanjani, emgqeni noma eshidini lesitayela,--bs-columns
kanye--bs-gap
.
Ngokuzayo, i-Bootstrap izoshintshela kusixazululo esiyingxubevange njengoba gap
indawo isizuze cishe ukusekelwa okugcwele kwesiphequluli se-flexbox.
Umehluko oyinhloko
Uma kuqhathaniswa nesistimu yegridi ezenzakalelayo:
-
Izinsiza ze-Flex awazithinti amakholomu eGridi ye-CSS ngendlela efanayo.
-
Izikhala zithatha indawo yama-gutters. Indawo
gap
ingena esikhundlenipadding
sokuvundlile kusistimu yethu yegridi ezenzakalelayo futhi isebenza njengemargin
. -
Kanjalo, ngokungafani no
.row
-s, u-.grid
s akanawo amamajini angemahle futhi izinsiza ze-margin azikwazi ukusetshenziselwa ukushintsha ama-gutters egridi. Izikhala zegridi zisetshenziswa ngokuvundlile nangokuqondile ngokuzenzakalelayo. Bona isigaba sokwenza ngendlela oyifisayo ukuze uthole imininingwane eyengeziwe. -
Izitayela ezingaphakathi komugqa nezingokwezifiso kufanele zibhekwe njengokuthatha indawo yezigaba zesilungisi (isb.,
style="--bs-columns: 3;"
ngokumeleneclass="row-cols-3"
). -
I-Nesting isebenza ngendlela efanayo, kodwa ingase idinge ukuthi usethe kabusha izibalo zekholomu yakho esimweni ngasinye se-nested
.grid
. Bona isigaba sokuzalela ukuze uthole imininingwane.
Izibonelo
Amakholomu amathathu
Amakholomu amathathu anobubanzi obulinganayo kuzo zonke izinkundla zokubuka namadivayisi angadalwa kusetshenziswa .g-col-4
amakilasi. Engeza amakilasi asabelayo ukuze ushintshe isakhiwo ngosayizi wembobo yokubuka.
<div class="grid">
<div class="g-col-4">.g-col-4</div>
<div class="g-col-4">.g-col-4</div>
<div class="g-col-4">.g-col-4</div>
</div>
Iyasabela
Sebenzisa amakilasi aphendulayo ukuze ulungise isakhiwo sakho kuzo zonke izimbobo zokubuka. Lapha siqala ngamakholomu amabili ezimbotsheni zokubuka ezincane kakhulu, bese sikhula sibe amakholomu amathathu ezimbobeni zokubuka ezimaphakathi nangaphezulu.
<div class="grid">
<div class="g-col-6 g-col-md-4">.g-col-6 .g-col-md-4</div>
<div class="g-col-6 g-col-md-4">.g-col-6 .g-col-md-4</div>
<div class="g-col-6 g-col-md-4">.g-col-6 .g-col-md-4</div>
</div>
Qhathanisa lokho nalesi sakhiwo samakholomu amabili kuzo zonke izinkundla zokubuka.
<div class="grid">
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
</div>
Ukusonga
Izinto zegridi zigoqa ngokuzenzakalelayo emugqeni olandelayo uma lingasekho igumbi elivundlile. Qaphela ukuthi lokhu gap
kusebenza ezikhaleni ezivundlile nezime mpo phakathi kwezinto zegridi.
<div class="grid">
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
</div>
Iqala
Amakilasi okuqala ahlose ukumiselela amakilasi ethu azenzakalelayo egridi, kodwa awafani nhlobo. Igridi ye-CSS idala isifanekiso segridi ngezitayela ezitshela iziphequluli ukuthi “ziqale kule kholomu” futhi “zigcine kule kholomu.” Lezo zakhiwo ziyi grid-column-start
futhi grid-column-end
. Amakilasi okuqala afushanisiwe kowokuqala. Wabhanqe namakilasi ekholomu ngosayizi futhi uqondanise amakholomu akho ngendlela oyidingayo. Amakilasi okuqala aqala 1
njengenani 0
elingavumelekile lalezi zici.
<div class="grid">
<div class="g-col-3 g-start-2">.g-col-3 .g-start-2</div>
<div class="g-col-4 g-start-6">.g-col-4 .g-start-6</div>
</div>
Amakholomu azenzakalelayo
Uma kungekho amakilasi ezintweni zegridi (izingane eziseduze ze-a .grid
), into ngayinye yegridi izolinganiswa ngokuzenzakalelayo ibe ikholomu eyodwa.
<div class="grid">
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
</div>
Lokhu kuziphatha kungaxutshwa namakilasi ekholomu yegridi.
<div class="grid">
<div class="g-col-6">.g-col-6</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
</div>
Ukwenza isidleke
Ngokufana nesistimu yethu yegridi ezenzakalelayo, Igridi yethu ye-CSS ivumela ukuzalela okulula kwe- .grid
s. Nokho, ngokungafani nokuzenzakalelayo, le gridi izuza njengefa izinguquko emigqeni, amakholomu, nezikhala. Cabangela isibonelo esingezansi:
- Sikhipha inombolo emisiwe yamakholomu ngokuhlukahluka kwendawo ye-CSS:
--bs-columns: 3
. - Kukholomu ezenzakalelayo yokuqala, isibalo sekholomu sizuzwa njengefa futhi ikholomu ngayinye iyingxenye eyodwa kwezintathu yobubanzi obutholakalayo.
- Kukholomu yesibili ezenzakalelayo, sisethe kabusha ukubala kwekholomu kokubekwe kusidleke
.grid
ku-12 (okuzenzakalelayo kwethu). - Ikholomu ezenzakalelayo yesithathu ayinakho okuqukethwe esidlekeni.
Empeleni lokhu kuvumela izakhiwo eziyinkimbinkimbi nezingokwezifiso uma kuqhathaniswa nesistimu yethu yegridi ezenzakalelayo.
<div class="grid" style="--bs-columns: 3;">
<div>
First auto-column
<div class="grid">
<div>Auto-column</div>
<div>Auto-column</div>
</div>
</div>
<div>
Second auto-column
<div class="grid" style="--bs-columns: 12;">
<div class="g-col-6">6 of 12</div>
<div class="g-col-4">4 of 12</div>
<div class="g-col-2">2 of 12</div>
</div>
</div>
<div>Third auto-column</div>
</div>
Ukwenza ngokwezifiso
Enza ngendlela oyifisayo inani lamakholomu, inani lemigqa, nobubanzi bezikhala ngokuhlukahluka kwendawo ye-CSS.
Iyaguquguquka | Inani lokubuyela emuva | Incazelo |
---|---|---|
--bs-rows |
1 |
Inani lemigqa kusifanekiso sakho segridi |
--bs-columns |
12 |
Inani lamakholomu kusifanekiso sakho segridi |
--bs-gap |
1.5rem |
Usayizi wegebe phakathi kwamakholomu (okuqondile nokuvundlile) |
Lezi zinhlobonhlobo ze-CSS azinalo inani elizenzakalelayo; esikhundleni salokho, zisebenzisa amanani okubuyela emuva asetshenziswa kuze kube yilapho kunikezwa isibonelo sasendaweni. Isibonelo, sisebenzisa var(--bs-rows, 1)
imigqa yethu Yegridi ye-CSS, eshaya indiva --bs-rows
ngoba lokho akukakasethwa noma kuphi. Uma sekunje, .grid
isibonelo sizosebenzisa lelo nani esikhundleni senani lokubuyela emuva lika- 1
.
Awekho amakilasi egridi
Izakhi ezisheshayo zezingane .grid
ziyizinto zegridi, ngakho zizolinganiswa ngaphandle kokwengeza .g-col
ikilasi ngokusobala.
<div class="grid" style="--bs-columns: 3;">
<div>Auto-column</div>
<div>Auto-column</div>
<div>Auto-column</div>
</div>
Amakholomu nezikhala
Lungisa inani lamakholomu kanye negebe.
<div class="grid" style="--bs-columns: 4; --bs-gap: 5rem;">
<div class="g-col-2">.g-col-2</div>
<div class="g-col-2">.g-col-2</div>
</div>
<div class="grid" style="--bs-columns: 10; --bs-gap: 1rem;">
<div class="g-col-6">.g-col-6</div>
<div class="g-col-4">.g-col-4</div>
</div>
Yengeza imigqa
Ukwengeza imigqa eyengeziwe nokushintsha ukubekwa kwamakholomu:
<div class="grid" style="--bs-rows: 3; --bs-columns: 3;">
<div>Auto-column</div>
<div class="g-start-2" style="grid-row: 2">Auto-column</div>
<div class="g-start-3" style="grid-row: 3">Auto-column</div>
</div>
Izikhala
Shintsha izikhala ezime mpo kuphela ngokulungisa ifayela le- row-gap
. Qaphela ukuthi sisebenzisa gap
ku- .grid
s, kodwa row-gap
futhi column-gap
singashintshwa njengoba kudingeka.
<div class="grid" style="row-gap: 0;">
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
</div>
Ngenxa yalokho, ungaba no- gap
s abaqondile nabavundlile abahlukene, okungathatha inani elilodwa (zonke izinhlangothi) noma amanani amabili (aqondile futhi avundlile). Lokhu kungasetshenziswa ngesitayela esingaphakathi komugqa se- gap
, noma ngokuhlukahluka kwethu kwe- --bs-gap
CSS.
<div class="grid" style="--bs-gap: .25rem 1rem;">
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
<div class="g-col-6">.g-col-6</div>
</div>
Sass
Umkhawulo owodwa weGridi ye-CSS ukuthi amakilasi ethu azenzakalelayo asakhiqizwa okuguquguqukayo okubili kwe-Sass, $grid-columns
kanye $grid-gutter-width
. Lokhu kunquma kusengaphambili ngempumelelo inani lamakilasi akhiqizwe ku-CSS yethu ehlanganisiwe. Unezinketho ezimbili lapha:
- Lungisa lezo ziguquguqukayo ezizenzakalelayo ze-Sass futhi uhlanganise kabusha i-CSS yakho.
- Sebenzisa izitayela ezingaphakathi komugqa noma zangokwezifiso ukuze ukhulise amakilasi anikeziwe.
Isibonelo, ungakwazi ukwandisa isibalo sekholomu futhi ushintshe usayizi wegebe, bese usayizi “amakholomu” akho ngenhlanganisela yezitayela ezisemgqeni kanye namakilasi ekholomu yegridi ye-CSS echazwe ngaphambilini (isb, .g-col-4
).
<div class="grid" style="--bs-columns: 18; --bs-gap: .5rem;">
<div style="grid-column: span 14;">14 columns</div>
<div class="g-col-4">.g-col-4</div>
</div>