Grid system
Gwiritsani ntchito gridi yathu yamphamvu yoyambira flexbox kuti mupange masanjidwe amitundu yonse ndi makulidwe ake chifukwa cha magawo khumi ndi awiri, magawo asanu omvera osakhazikika, zosinthika za Sass ndi zosakaniza, ndi makalasi ambiri omwe adafotokozedwatu.
Dongosolo la grid ya Bootstrap limagwiritsa ntchito zotengera zingapo, mizere, ndi mizere kuti isanjidwe ndikugwirizanitsa zomwe zili. Imapangidwa ndi flexbox ndipo imayankha kwathunthu. Pansipa pali chitsanzo ndi kuyang'ana mozama momwe gululi limakhalira pamodzi.
Zatsopano kapena simukuzidziwa ndi flexbox? Werengani izi CSS Tricks flexbox guide for background, terminology, guidelines, ndi code snippets.
Chitsanzo chapamwambachi chimapanga mizati itatu yofanana m'lifupi pazida zazing'ono, zapakati, zazikulu, ndi zazikulu zowonjezera pogwiritsa ntchito makalasi athu omwe tawafotokozeratu. Mizati imeneyo ili pakati pa tsamba ndi kholo .container
.
Kuyiphwanya, nayi momwe imagwirira ntchito:
- Zotengera zimakupatsirani njira yokhazikitsira pakati ndikuwongolera mopingasa zomwe zili patsamba lanu. Gwiritsani ntchito kukula kwa
.container
pixel komvera kapena pamawonekedwe onse ndi makulidwe a chipangizo..container-fluid
width: 100%
- Mizere ndi zokutira pamizere. Chigawo chilichonse chili ndi chopingasa
padding
(chotchedwa gutter) chowongolera danga pakati pawo. Izipadding
ndiye zimatsutsidwa pamizere yokhala ndi malire olakwika. Mwanjira iyi, zonse zomwe zili m'mipingo yanu zimayang'aniridwa kumanzere. - Pamasanjidwe a gridi, zomwe zili mumizere ziyenera kuyikidwa m'mizere ndipo magawo okhawo omwe angakhale ana amizere.
- Chifukwa cha flexbox, mizati ya gridi popanda kutchulidwa
width
imangokhazikitsidwa ngati mizere yofanana m'lifupi. Mwachitsanzo, magawo anayi amtundu.col-sm
uliwonse adzakhala 25% m'lifupi kuchokera pagawo laling'ono kupita mmwamba. Onani gawo lazopanga zokha kuti mupeze zitsanzo zambiri. - Makalasi amizere amawonetsa kuchuluka kwa magawo omwe mukufuna kugwiritsa ntchito pa 12 pa mzere uliwonse. Chifukwa chake, ngati mukufuna mizati itatu yopingasa yofanana, mutha kugwiritsa ntchito
.col-4
. - Mizati
width
s imayikidwa muzochulukira, kotero nthawi zonse imakhala yamadzimadzi komanso yokulirapo poyerekeza ndi gawo la makolo awo. - Mizati imakhala yopingasa
padding
kuti ipange ngalande pakati pa mizati payokha, komabe, mutha kuchotsamargin
mizere ndi mizerepadding
yokhala.no-gutters
ndi.row
. - Kuti gululi liziyankha, pali zodulitsa ma gridi asanu, imodzi pagawo lililonse loyankhidwa : ma breakpoints onse (owonjezera ang'onoang'ono), ang'onoang'ono, apakatikati, akulu, ndi akulu owonjezera.
- Kudumpha kwa ma gridi kumatengera mafunso ochepera a m'lifupi mwake, kutanthauza kuti amagwira ntchito pagawo limodzi ndi onse omwe ali pamwamba pake (mwachitsanzo,
.col-sm-4
zimagwira ntchito pazida zazing'ono, zapakati, zazikulu, ndi zazikulu, koma osati poyambiraxs
). - Mutha kugwiritsa ntchito makalasi ofotokozedweratu (monga
.col-4
) kapena ma Sass ophatikizika kuti musinthe mawonekedwe.
Dziwani zoperewera ndi nsikidzi kuzungulira flexbox , monga kulephera kugwiritsa ntchito zinthu zina za HTML ngati zotengera zosinthika .
Pomwe Bootstrap imagwiritsa ntchito em
s kapena rem
s kutanthauzira makulidwe ambiri, px
s amagwiritsidwa ntchito podulira ma gridi ndi m'lifupi mwake. Izi zili choncho chifukwa m'lifupi mwake malo owonera ndi ma pixel ndipo sasintha ndi kukula kwa mawonekedwe .
Onani momwe ma gridi a Bootstrap amagwirira ntchito pazida zingapo zokhala ndi tebulo lothandizira.
Zocheperako < 576px |
Yaing'ono ≥576px |
Wapakatikati ≥768px |
Chachikulu ≥992px |
Chachikulu kwambiri ≥1200px |
|
---|---|---|---|---|---|
M'lifupi mwake | Palibe (yokha) | 540px | 720px | 960px | 1140px |
Chiyambi cha kalasi | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
# ya mizati | 12 | ||||
Kuchuluka kwa ngalande | 30px (15px mbali iliyonse ya ndime) | ||||
Nestable | Inde | ||||
Kuyitanitsa ndindalama | Inde |
Gwiritsani ntchito makalasi a magawo enieni a magawo kuti musinthe magawo mosavuta popanda kalasi yodziwika bwino ngati .col-sm-6
.
Mwachitsanzo, apa pali mitundu iwiri ya gridi yomwe imagwira ntchito pa chipangizo chilichonse ndi malo owonera, kuyambira xs
mpaka xl
. Onjezani kuchuluka kwa makalasi opanda ma unit pagawo lililonse lomwe mungafune ndipo gawo lililonse likhala lofanana m'lifupi.
Mizati yofanana m'lifupi imatha kuthyoledwa m'mizere ingapo, koma panali cholakwika cha Safari flexbox chomwe chinalepheretsa izi kugwira ntchito popanda kumveka flex-basis
kapena border
. Pali ma workaround amitundu akale asakatuli, koma siziyenera kukhala zofunikira ngati mukusintha.
Kukonzekera kwa Auto kwa mizati ya grid flexbox kumatanthauzanso kuti mutha kuyika m'lifupi mwagawo limodzi ndikupangitsa kuti mizere ya abale anu isinthe kukula mozungulira. Mutha kugwiritsa ntchito makalasi ofotokozedweratu (monga momwe tawonetsera pansipa), zophatikizira za gridi, kapena makulidwe amzere. Zindikirani kuti mizati ina idzakula mosasamala kanthu za kukula kwa ndime yapakati.
Gwiritsani ntchito col-{breakpoint}-auto
makalasi kuti agwirizane ndi kukula kwake kwazomwe zili.
Pangani mizati yotalika yofanana yomwe imayenda mizere ingapo poyikapo .w-100
pomwe mukufuna kuti mizere iduke pamzere watsopano. Pangani nthawi yopuma kuti iyankhe posakaniza .w-100
ndi zina zowonetsera zowonetsera .
Gululi la Bootstrap limaphatikizapo magawo asanu a makalasi omwe adafotokozedwatu kuti amange masanjidwe ovuta kuyankha. Sinthani kukula kwa mizati yanu pazida zing'onozing'ono, zazing'ono, zapakatikati, zazikulu, kapena zazikulu monga momwe mungafunire.
Kwa ma gridi omwe ali ofanana kuyambira pazida zazing'ono kwambiri mpaka zazikulu, gwiritsani ntchito .col
ndi .col-*
makalasi. Tchulani kalasi yowerengeka pamene mukufuna gawo lalikulu; apo ayi, khalani omasuka kumamatira .col
.
Pogwiritsa ntchito gulu limodzi la .col-sm-*
makalasi, mutha kupanga makina oyambira a gridi omwe amayambira atakusanjidwa ndikukhala opingasa pagawo laling'ono ( sm
).
Kodi simukufuna kuti zipilala zanu zizingounjika m'magulu ena a gridi? Gwiritsani ntchito makalasi osiyanasiyana pagawo lililonse ngati pakufunika. Onani chitsanzo pansipa kuti mudziwe bwino momwe zonsezi zimagwirira ntchito.
Gwiritsani ntchito zida zoyankhulirana za flexbox kuti mulumikizane molunjika komanso mopingasa.
Miyendo pakati pa mizati m'magulu athu omwe tafotokozeratu amatha kuchotsedwa ndi .no-gutters
. Izi zimachotsa zoipa margin
s kuchokera .row
ndi yopingasa padding
kuchokera mzati zonse za ana.
Nayi code yoyambira yopangira masitayelo awa. Zindikirani kuti zotuluka m'mipingo zimangoyang'aniridwa ndi ana oyamba okha ndipo amangosankhidwa posankha zilembo . Ngakhale kuti izi zimapanga chosankha chodziwika bwino, padding pazidutswa imatha kusinthidwanso ndi zida zapakati .
Mukufuna mapangidwe am'mphepete mpaka m'mphepete? Kugwetsa kholo .container
kapena .container-fluid
.
Mwakuchita, umu ndi momwe zimawonekera. Zindikirani kuti mutha kupitiliza kugwiritsa ntchito izi ndi makalasi ena onse omwe afotokozedweratu (kuphatikiza makulidwe amzere, magawo omvera, kuyitanitsa, ndi zina zambiri).
Ngati mizati yopitilira 12 yayikidwa pamzere umodzi, gulu lililonse la zigawo zowonjezera, ngati gawo limodzi, likulungidwa pamzere watsopano.
Popeza 9 + 4 = 13 > 12, div-column-wide iyi 4 imakutidwa pamzere watsopano ngati gawo limodzi lolumikizana.
Mizati yotsatira ikupitilira pamzere watsopano.
Kuthyola zipilala ku mzere watsopano mu flexbox kumafuna kuthyolako pang'ono: onjezani chinthu ndi width: 100%
paliponse pomwe mukufuna kukulunga mizati yanu ku mzere watsopano. Kawirikawiri izi zimachitika ndi ma multiples .row
, koma si njira zonse zogwiritsira ntchito zomwe zingathe kuwerengera izi.
Mutha kugwiritsanso ntchito nthawi yopumirayi pakanthawi kochepa ndi zida zathu zowonetsera .
Gwiritsani ntchito .order-
makalasi kuwongolera mawonekedwe azinthu zanu. Maphunzirowa ndi omvera, kotero mutha kukhazikitsa order
ndi breakpoint (mwachitsanzo, .order-1.order-md-2
). Zimaphatikizapo chithandizo chamagulu onse asanu 1
a 12
gridi.
Palinso makalasi omvera .order-first
komanso .order-last
omwe amasintha order
chinthucho pogwiritsa ntchito order: -1
ndi order: 13
( order: $columns + 1
), motsatana. Maphunzirowa amathanso kusakanikirana ndi .order-*
makalasi owerengeka ngati pakufunika.
Mutha kusintha magawo a gridi m'njira ziwiri: .offset-
makalasi athu omvera a gridi ndi zida zathu zam'mphepete . Magulu a gridi amakula kuti agwirizane ndi mipingo pomwe m'mphepete mwake ndi othandiza kwambiri pamasanjidwe ofulumira pomwe m'lifupi mwake ndikusintha.
Sunthani mizati kumanja pogwiritsa ntchito .offset-md-*
makalasi. Makalasi awa amawonjezera malire akumanzere kwa gawo ndi magawo *
. Mwachitsanzo, .offset-md-4
amasuntha .col-md-4
mizati inayi.
Kuphatikiza pa kukonza magawo pazigawo zongoyankha, mungafunike kukonzanso zosintha. Onani izi muzochitika mu grid chitsanzo .
Ndi kusunthira ku flexbox mu v4, mutha kugwiritsa ntchito zida zam'mphepete monga .mr-auto
kukakamiza mizere ya abale kutali.
Kuti mutsegule zomwe zili ndi gridi yokhazikika, onjezani magawo atsopano .row
ndi magulu omwe ali .col-sm-*
mgulu lomwe lilipo .col-sm-*
. Mizere yokhazikitsidwa iyenera kukhala ndi magawo 12 kapena kucheperapo (sikufunika kuti mugwiritse ntchito magawo 12 onse omwe alipo).
Mukamagwiritsa ntchito mafayilo a Sass a Bootstrap, muli ndi mwayi wogwiritsa ntchito zosinthika za Sass ndi zosakaniza kuti mupange masanjidwe amasamba, a semantic, ndi omvera. Makalasi athu omwe adafotokozedwatu amagwiritsa ntchito zosinthika zomwezi ndi zosakaniza kuti apereke gulu lonse la makalasi okonzeka kugwiritsa ntchito masanjidwe omvera mwachangu.
Zosintha ndi mamapu zimatsimikizira kuchuluka kwa mizati, m'lifupi mwa ngalande, ndi malo ochezera a pawailesi pomwe amayambira mizati yoyandama. Timagwiritsa ntchito izi kupanga makalasi a gridi omwe afotokozedwa pamwambapa, komanso zosakaniza zomwe zalembedwa pansipa.
Mixins amagwiritsidwa ntchito molumikizana ndi ma gridi osiyanasiyana kuti apange CSS ya semantic pamizere ya gridi iliyonse.
Mutha kusintha zosinthika kukhala zomwe mumakonda, kapena ingogwiritsani ntchito zosakaniza zomwe zili ndi zikhalidwe zawo. Nachi chitsanzo chogwiritsa ntchito zosintha zosasinthika kuti mupange masanjidwe a magawo awiri okhala ndi kusiyana pakati.
Pogwiritsa ntchito zosinthika zathu za grid Sass ndi mamapu, ndizotheka kusinthiratu magulu omwe tawafotokozeratu. Sinthani kuchuluka kwa ma tiers, miyeso yamafunso a media, ndi makulidwe a chidebe - kenaka phatikizaninso.
Chiwerengero cha mizere ya gridi chikhoza kusinthidwa kudzera mumitundu ya Sass. $grid-columns
amagwiritsidwa ntchito kupanga m'lifupi (mu peresenti) ya ndime iliyonse payekha $grid-gutter-width
ndikuyika m'lifupi mwazitsulo zazitsulo.
Kupitilira mizati yokha, mutha kusinthanso kuchuluka kwa ma grid tiers. Ngati mumangofuna magawo anayi a gridi, mutha kusintha $grid-breakpoints
ndi $container-max-widths
zina monga izi:
Mukapanga zosintha zilizonse pamitundu kapena mamapu a Sass, muyenera kusunga zosintha zanu ndikubwezeretsanso. Kuchita izi kudzatulutsa gulu latsopano lamagulu ofotokozedweratu amtundu wa magawo, ma offsets, ndi kuyitanitsa. Zida zowonekera zidzasinthidwanso kuti zigwiritse ntchito ma breakpoints. Onetsetsani kuti mwakhazikitsa ma grid mu px
(osati rem
, em
, kapena %
).