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.
Momwe zimagwirira ntchito
Dongosolo la grid ya Bootstrap limagwiritsa ntchito zotengera zingapo, mizere, ndi mizati kuti isanjidwe ndikugwirizanitsa zomwe zili. Imapangidwa ndi flexbox ndipo imayankha kwathunthu. M'munsimu muli 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 .
Zosankha zamagulu
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 machitidwe a gridi ya 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 |
Zopanga zokha mizati
Gwiritsani ntchito makalasi a magawo enieni a magawo kuti musinthe magawo mosavuta popanda kalasi yodziwika bwino ngati .col-sm-6
.
Kufanana m'lifupi
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.
Equal-width mizere yambiri
Pangani mizati yofanana m'lifupi mwake yomwe imayenda mizere ingapo poyikapo .w-100
pomwe mukufuna kuti mizere iduke pamzere watsopano. Pangani nthawi yopuma kuti igwirizane ndi kusakanikirana .w-100
ndi zida zina zowonetsera .
Panali cholakwika cha Safari flexbox chomwe chidalepheretsa izi kugwira ntchito popanda kumveka flex-basis
kapena border
. Pali ma workaround amitundu akale asakatuli, koma siziyenera kukhala zofunikira ngati asakatuli omwe mukufuna sakugwera m'mitundu ya ngolo.
Kukhazikitsa m'lifupi ndime imodzi
Kukonzekera kwa Auto kwa mizati ya grid flexbox kumatanthauzanso kuti mutha kuyika m'lifupi mwagawo limodzi ndikukhala ndi magawo am'bale mozungulira mozungulira. Mutha kugwiritsa ntchito makalasi ofotokozedweratu (monga momwe tawonetsera pansipa), zosakaniza za gridi, kapena makulidwe amzere. Dziwani kuti mizati ina idzakula mosasamala kanthu za kukula kwa ndime yapakati.
Zosintha m'lifupi mwake
Gwiritsani ntchito col-{breakpoint}-auto
makalasi kuti agwirizane ndi kukula kwake kwazomwe zili.
Makalasi omvera
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.
Ma breakpoints onse
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
.
Zaunikidwa mpaka yopingasa
Pogwiritsa ntchito gulu limodzi la .col-sm-*
makalasi, mutha kupanga makina oyambira a gridi omwe amayambira atakusanjidwa ndikukhala opingasa pagawo laling'ono ( sm
).
Sakanizani ndikugwirizanitsa
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.
Mitsinje
Ma gutter amatha kusinthidwa bwino ndi ma breakpoint-Specific padding ndi makalasi ogwiritsira ntchito m'mphepete. Kuti musinthe ma gutters pamzere woperekedwa, phatikizani chogwiritsira ntchito pamphepete .row
ndi zofananira pa .col
s. Kholo .container
kapena .container-fluid
kholo lingafunike kusinthidwanso kuti lipewe kusefukira kosayenera, kugwiritsanso ntchito zofananira.
Nachi chitsanzo chakusintha grid ya Bootstrap pamalo akulu ( lg
) breakpoint ndi pamwambapa. Tawonjezera .col
zotchingira ndi .px-lg-5
, kutsutsa ndi .mx-lg-n5
pa kholo .row
kenako ndikusintha .container
chokulunga ndi .px-lg-5
.
Mizere mizere
Gwiritsani ntchito .row-cols-*
makalasi omvera kuti mukhazikitse mwachangu kuchuluka kwa magawo omwe amakupangitsani bwino zomwe zili ndi masanjidwe anu. Pamene .col-*
makalasi anthawi zonse amagwira ntchito pamigawo iliyonse (mwachitsanzo, .col-md-4
), makalasi amizere amayikidwa pa kholo .row
ngati njira yachidule.
Gwiritsani ntchito makalasi amizeremizerewa kuti mupange mwachangu masanjidwe a gridi kapena kuwongolera masanjidwe a makadi anu.
Mukhozanso kugwiritsa ntchito Sass mixin, row-cols()
:
Kuyanjanitsa
Gwiritsani ntchito zida zoyankhulirana za flexbox kuti mulumikizane molunjika komanso mopingasa. Internet Explorer 10-11 sichirikiza kuyanjanitsa koyima kwa zinthu zosinthika pomwe chidebe chosinthira chili ndi zomwe zili min-height
pansipa. Onani Flexbugs #3 kuti mumve zambiri.
Kuyanjanitsa koyima
Kuyanjanitsa kopingasa
Palibe ngalande
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'migawo zimangoyang'aniridwa ndi ana oyamba okha ndipo amangosankhidwa posankha zilembo . Ngakhale izi zimapanga chosankha chodziwika bwino, padding pamizere imatha kusinthidwanso ndi zida zopangira masitayilo .
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 adafotokozedweratu (kuphatikiza makulidwe amzere, magawo omvera, kuyitanitsa, ndi zina zambiri).
Kuzimata ndime
Ngati mizati yopitilira 12 yayikidwa pamzere umodzi, gulu lililonse la zigawo zowonjezera, ngati gawo limodzi, likulungidwa pamzere watsopano.
Popeza 9 + 4 = 13 > 12, div ya 4-column-wide iyi imakutidwa pamzere watsopano ngati gawo limodzi lolumikizana.
Mizati yotsatira ikupitilira pamzere watsopano.
Kuthyoka kwa magawo
Kuthyola mizati ku mzere watsopano mu flexbox kumafuna kuthyolako pang'ono: onjezani chinthu ndi width: 100%
paliponse pamene 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 .
Kuyitanitsanso
Onjezani makalasi
Gwiritsani ntchito .order-
makalasi kuwongolera mawonekedwe azinthu zanu. Maphunzirowa ndi omvera, kotero mutha kukhazikitsa order
ndi breakpoint (mwachitsanzo, .order-1.order-md-2
). Zimaphatikizansopo 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.
Kuchepetsa mizati
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.
Maphunziro a Offset
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 .
Zida zam'mphepete
Ndi kusunthira ku flexbox mu v4, mutha kugwiritsa ntchito zida zam'mphepete monga .mr-auto
kukakamiza mizere ya abale kutali.
Nesting
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).
Zosakaniza za Sass
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 tawafotokozeratu amagwiritsa ntchito zosinthika zomwezi ndi zosakaniza kuti apereke gulu lonse la makalasi okonzeka kugwiritsa ntchito masanjidwe omvera mwachangu.
Zosintha
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.
Zosakaniza
Ma Mixin amagwiritsidwa ntchito molumikizana ndi ma gridi osiyanasiyana kuti apange CSS ya semantic pamizere ya gridi iliyonse.
Kugwiritsa ntchito chitsanzo
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.
Kusintha gridi mwamakonda anu
Pogwiritsa ntchito zosinthika zathu za grid Sass ndi mamapu, ndizotheka kusinthiratu magulu omwe tawafotokozeratu. Sinthani kuchuluka kwa magawo, miyeso yafunso la media, ndi makulidwe a chidebe - kenaka phatikizaninso.
Mizere ndi ngalande
Chiwerengero cha ma grid columns 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 mwa magutters amzati.
Mitundu ya gridi
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 pamapu a Sass kapena mamapu, muyenera kusunga zosintha zanu ndikubwezeretsanso. Kuchita izi kutulutsa gulu latsopano lamagulu ofotokozedweratu amtundu wa magawo, ma offset, ndi kuyitanitsa. Zida zowonekera zidzasinthidwanso kuti zigwiritse ntchito ma breakpoints. Onetsetsani kuti mwakhazikitsa ma grid mu px
(osati rem
, em
, kapena %
).