Sistimi ea grid
Sebelisa marang-rang a rona a matla a mobile-first flexbox ho aha meralo ea libopeho le boholo bohle ka lebaka la sistimi ea likholomo tse leshome le metso e 'meli, mekhahlelo e mehlano e arabelang ka ho sa feleng, mefuta ea Sass le metsoako, le lihlopha tse ngata tse boletsoeng esale pele.
Sistimi ea grid ea Bootstrap e sebelisa letoto la lijana, mela le likholomo ho hlophisa le ho hokahanya litaba. E hahiloe ka flexbox 'me e arabela ka botlalo. Ka tlase ke mohlala le pono e tebileng ea hore na marang-rang a kopana joang.
Na u sa tsoa tloaelana le flexbox? Bala tataiso ena ea CSS Tricks flexbox bakeng sa bokamorao, poleloana, litataiso, le likotlo tsa khoutu.
Mohlala o ka holimo o theha likholomo tse tharo tse bophara bo lekanang ho lisebelisoa tse nyane, tse mahareng, tse kholo le tse kholo ho feta ho sebelisa litlelase tsa rona tse boletsoeng esale pele. Likholomo tseo li bohareng ba leqephe la motsoali .container
.
Ho e senya, ke kamoo e sebetsang kateng:
- Lits'oants'o li fana ka mokhoa oa ho beha bohareng le ho tsamaisa litaba tsa sebaka sa hau sa marang-rang. Sebelisa
.container
bakeng sa bophara ba pixel bo arabelang kapa.container-fluid
bakeng sawidth: 100%
libaka tsohle tsa pono le boholo ba lisebelisoa. - Mela ke wrappers bakeng sa likholomo. Kholomo e 'ngoe le e 'ngoe e na le sebaka se
padding
otlolohileng (se bitsoang gutter) bakeng sa ho laola sebaka se pakeng tsa tsona. Joale senapadding
se hanyetsoa meleng e nang le mathoko a mabe. Ka tsela ena, litaba tsohle tse likholomong tsa hau li hokahane ka pono ho theosa le lehlakore le letšehali. - Ka moralo oa marang-rang, likahare li tlameha ho behoa ka har'a likholomo 'me likholomo feela e ka ba bana ba haufi ba mela.
- Ka lebaka la flexbox, li-columns tsa grid ntle le tse boletsoeng
width
li tla hlophisoa ka bohona e le likholomo tse lekanang tsa bophara. Ka mohlala, liketsahalo tse 'nè tsa.col-sm
e mong le e mong e tla ba bophara ba 25% ho tloha sebakeng se senyenyane ho ea holimo. Sheba karolo ea li-columns tsa moralo o ikemetseng bakeng sa mehlala e meng. - Lihlopha tsa kholomo li bontša palo ea likholomo tseo u ka ratang ho li sebelisa ho tse ka bang 12 ka mola. Kahoo, haeba u batla likholomo tse tharo tse bophara bo lekanang ka bophara, u ka sebelisa
.col-4
. - Kholomo
width
s li behiloe ka liphesente, kahoo li lula li le metsi 'me li lekana le karolo ea motsoali oa tsona. - Likholomo li na le tse rapameng
padding
ho theha likhoele lipakeng tsa litšiea ka bomong, leha ho le joalo, o ka tlosamargin
mela lepadding
likholomo tse nang.no-gutters
le.row
. - Ho etsa hore grid e arabele, ho na le li-breakpoints tse hlano, e le 'ngoe bakeng sa sebaka se seng le se seng se arabelang : li-breakpoints kaofela (tse nyane haholo), tse nyane, tse mahareng, tse kholo, le tse kholo ho feta.
- Li-breakpoints tsa grid li ipapisitse le lipotso tsa media tse bophara bo tlase, ho bolelang hore li sebetsa sebakeng se le seng le tse ka holimo ho eona (mohlala,
.col-sm-4
li sebetsa ho lisebelisoa tse nyane, tse mahareng, tse kholo le tse kholo, empa eseng sebaka sa pelexs
). - U ka sebelisa litlelase tsa grid tse boletsoeng esale pele (joaloka
.col-4
) kapa li-mix tsa Sass bakeng sa markup ea semantic.
Ela hloko mefokolo le litšitšili tse potolohileng flexbox , joalo ka ho se khone ho sebelisa likarolo tse ling tsa HTML joalo ka lijana tsa flex .
Leha Bootstrap e sebelisa em
s kapa rem
s bakeng sa ho hlalosa boholo ba boholo, px
s e sebelisoa bakeng sa likheo tsa marang-rang le bophara ba setshelo. Lebaka ke hobane bophara ba sebaka sa pono bo ka lipikselse 'me ha bo fetohe le boholo ba fonte .
Bona hore na likarolo tsa sistimi ea Bootstrap li sebetsa joang ho lisebelisoa tse ngata tse nang le tafole e sebetsang.
E nyane haholo <576px |
E nyane ≥576px |
Hare ≥768px |
E kholo ≥992px |
E kholo haholo ≥1200px |
|
---|---|---|---|---|---|
Boholo ba bophara ba setshelo | Ha ho letho (auto) | 540px | 720px | 960px | 1140px |
Sehlongoapele sa sehlopha | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
# ea likholomo | 12 | ||||
Bophara ba sekoti | 30px (15px ka lehlakoreng le leng la kholomo) | ||||
Nestable | Ee | ||||
Ho laela ka kholomo | Ee |
Sebelisa litlelase tse khethehileng tsa likholomo bakeng sa ho etsa boholo bo bonolo ba likholomo ntle le sehlopha se nang le linomoro tse hlakileng joalo ka .col-sm-6
.
Mohlala, mona ho na le meralo e 'meli ea marang-rang e sebetsang sesebelisoa se seng le se seng le sebaka sa pono, ho tloha xs
ho xl
. Kenya palo efe kapa efe ea litlelase tse se nang li-unit sebakeng se seng le se seng seo u se hlokang 'me kholomo e' ngoe le e 'ngoe e tla lekana ka bophara.
Likholomo tse bophara bo lekanang li ka aroloa ka mela e mengata, empa ho ne ho e-na le Safari flexbox bug e neng e thibela sena ho sebetsa ntle le ho hlaka flex-basis
kapa border
. Ho na le li-workaround bakeng sa liphetolelo tsa khale tsa sebatli, empa ha lia lokela ho hlokahala haeba u le nakong.
Ponahalo e iketsang bakeng sa likholomo tsa gridbox ea flexbox e boetse e bolela hore o ka seta bophara ba kholumo e le 'ngoe ebe o etsa hore litšiea tsa banab'eno li ikemisetse ho e potoloha. U ka sebelisa litlelase tsa grid tse boletsoeng esale pele (joalo ka ha ho bonts'itsoe ka tlase), li-mixins tsa grid, kapa bophara ba inline. Hlokomela hore litšiea tse ling li tla fetola boholo ho sa tsotellehe bophara ba kholomo e bohareng.
Sebelisa col-{breakpoint}-auto
litlelase ho isa likholomong tsa boholo ho ipapisitsoe le bophara ba tlhaho ba litaba tsa tsona.
Etsa likholomo tse bophara bo lekanang tse pharallang mela e mengata ka ho kenya .w-100
moo u batlang hore litšiea li khaole moleng o mocha. Etsa hore khefu e sebetse ka ho kopanya .w-100
lisebelisoa tse ling tse arabelang .
Gridi ea Bootstrap e kenyelletsa mekhahlelo e mehlano ea litlelase tse boletsoeng esale pele bakeng sa ho aha meralo e rarahaneng e arabelang. Iketsetse boholo ba litšiea tsa hau ho lisebelisoa tse nyane, tse nyane, tse mahareng, tse kholo kapa tse kholo ho feta kamoo u bonang ho loketse.
Bakeng sa marang-rang a ts'oanang ho tloha ho lisebelisoa tse nyane ho isa ho tse kholo, sebelisa .col
le .col-*
litlelase. Hlalosa sehlopha sa linomoro ha u hloka kholomo e boholo bo khethehileng; ho seng joalo, ikutloe u lokolohile ho khomarela .col
.
U sebelisa sehlopha se le seng sa .col-sm-*
litlelase, u ka theha sistimi ea mantlha ea grid e qalang e phuthetsoe ebe e ba e tšekaletseng sebakeng se senyenyane ( sm
).
Ha u batle hore litšiea tsa hau li kenelle ka har'a lihlopha tse ling tsa grid? Sebelisa motsoako oa lihlopha tse fapaneng bakeng sa mokhahlelo ka mong kamoo ho hlokahalang. Sheba mohlala o ka tlase bakeng sa mohopolo o betere oa hore na tsohle li sebetsa joang.
Sebelisa lisebelisoa tsa tekano ea flexbox ho hokahanya likholomo tse otlolohileng le tse tšekaletseng.
Li-gutters tse pakeng tsa litšiea lihlopheng tsa rona tse hlalositsoeng esale pele li ka tlosoa ka .no-gutters
. Sena se tlosa negative margin
s ho tloha .row
le tse rapameng padding
ho tloha likholomong tsohle tse haufi tsa bana.
Mona ke khoutu ea mohloli oa ho theha mefuta ena. Ela hloko hore ho fetisa kholomo ho fetisetsoa ho likholomo tsa bana ba pele feela 'me ho tobisitsoe ka khetho ea litšobotsi . Le hoja sena se hlahisa khetho e khethehileng haholoanyane, padding ea li-column e ntse e ka ntlafatsoa le ho feta ka lisebelisoa tsa sebaka .
Na u hloka moralo o mong le o mong? Lahla motsoali .container
kapa .container-fluid
.
Ka ts'ebetso, mona ke kamoo e shebahalang kateng. Hlokomela hore o ka tsoela pele ho sebelisa sena ka litlelase tse ling tsohle tse boletsoeng esale pele (ho kenyeletsoa bophara ba kholomo, likarolo tse arabelang, li-odara, le tse ling).
Haeba likholomo tse fetang 12 li behiloe ka har'a mola o le mong, sehlopha ka seng sa likholomo tse eketsehileng se tla thatela mola o mocha e le yuniti e le 'ngoe.
Ho tloha ha 9 + 4 = 13 > 12, div ena ea 4-column-wide e thatela moleng o mocha joalo ka yuniti e le 'ngoe e kopaneng.
latelang li tsoela pele moleng o mocha.
Ho pshatla litšiea ho ea moleng o mocha ka har'a flexbox ho hloka ts'ebetso e nyane: eketsa element ka width: 100%
hohle moo u batlang ho phuthela likholomo tsa hau moleng o mocha. Ka tloaelo sena se finyelloa ka li-multiple .row
s, empa ha se mokhoa o mong le o mong oa ts'ebetsong o ka ikarabellang bakeng sa sena.
U ka boela ua sebelisa khefu ena libakeng tse ikhethileng ka lisebelisoa tsa rona tse arabelang .
Sebelisa .order-
litlelase ho laola tatellano ea pono ea litaba tsa hau. Litlelase tsena lia arabela, ka hona, u ka khona ho beha sebaka sa " order
breakpoint" (mohlala, .order-1.order-md-2
). E kenyelletsa tšehetso bakeng sa 1
ho 12
pholletsa le mekhahlelo eohle e mehlano ea grid.
Ho boetse ho na le lihlopha tse arabelang .order-first
le .order-last
tse fetolang order
ntho ka ho sebelisa order: -1
le order: 13
( order: $columns + 1
), ka ho latellana. Litlelase tsena le tsona li ka tsoakoa le .order-*
lihlopha tse baloang ka linomoro ha ho hlokahala.
O ka hlakola likholomo tsa grid ka mekhoa e 'meli: .offset-
litlelase tsa rona tse arabelang le lisebelisoa tsa rona tsa marang-rang . Lihlopha tsa li-grid li lekane ho bapisa likholomo ha li-margin li le molemo haholo bakeng sa meralo e potlakileng moo bophara ba offset bo fetohang.
Tsamaisa likholomo ka ho le letona u sebelisa .offset-md-*
lihlopha. Lihlopha tsena li eketsa karolo e ka ho le letšehali ea kholomo ka *
likholomo. Ka mohlala, .offset-md-4
e tsamaea .col-md-4
ka holim'a likholomo tse 'nè.
Ntle le ho hlakola likholomo libakeng tse arabelang, ho ka 'na ha hlokahala hore u tsosolose li-offsets. Sheba sena ka liketso mohlaleng oa marang-rang .
Ka ho fallela ho flexbox ho v4, u ka sebelisa lisebelisoa tsa marang-rang tse kang .mr-auto
ho qobella litšiea tsa bana ba motho ho tloha ho tse ling.
Ho beha litaba tsa hau ka gridi ea kamehla, eketsa likholomo tse ncha .row
ka .col-sm-*
har'a .col-sm-*
kholomo e teng. Mela e hlophiloeng e tlameha ho kenyelletsa sehlopha sa likholomo tse kopanyang ho fihla ho 12 kapa ka tlase ho moo (ha ho hlokahale hore u sebelise likholomo tse 12 tse teng).
Ha u sebelisa lifaele tsa Sass tsa mohloli oa Bootstrap, u na le boikhethelo ba ho sebelisa mefuta-futa ea Sass le metsoako ho theha meralo ea maqephe a tloaelehileng, a semantic le a arabelang. Lihlopha tsa rona tsa marang-rang tse hlalositsoeng esale pele li sebelisa mefuta e tšoanang le metsoako ho fana ka lihlopha tse loketseng ho sebelisoa bakeng sa meralo e arabelang ka potlako.
Lintho tse feto-fetohang le limmapa li khetholla palo ea litšiea, bophara ba lithapo, le sebaka sa lipotso tsa mecha ea phatlalatso moo ho ka qalisoang litšiea tse phaphametseng. Re sebelisa tsena ho hlahisa lihlopha tsa marang-rang tse hlalositsoeng ka holimo, hammoho le li-mixins tse tloaelehileng tse thathamisitsoeng ka tlase.
Li-mixins li sebelisoa hammoho le mefuta e fapaneng ea grid ho hlahisa CSS ea semantic bakeng sa likholomo tsa grid ka bomong.
U ka fetola mefuta e fapaneng ho ea ho litekanyetso tsa hau tsa tloaelo, kapa u sebelise li-mixins ka boleng ba tsona ba kamehla. Mohlala ke ona oa ho sebelisa li-setting tsa kamehla ho theha sebopeho sa likholomo tse peli se nang le lekhalo lipakeng.
U sebelisa mefuta e fapaneng ea li-grid tsa Sass le limmapa tsa rona, hoa khonahala ho etsa litlelase tsa grid tse boletsoeng esale pele. Fetola palo ea li-tiers, litekanyo tsa lipotso tsa mecha ea litaba, le bophara ba setshelo - ebe u kopanya hape.
Palo ea likholomo tsa grid e ka fetoloa ka mefuta ea Sass. $grid-columns
e sebelisoa ho hlahisa bophara (ka liphesente) tsa kholomo e 'ngoe le e' ngoe ha e ntse $grid-gutter-width
e beha bophara ba li-gutters tsa kholomo.
Ho fetela ka nģ'ane ho litšiea ka botsona, u ka boela ua etsa palo ea lihlopha tsa grid. Haeba u ne u batla li-grid tse 'ne feela, u ka ntlafatsa $grid-breakpoints
le $container-max-widths
ho hong ho kang ena:
Ha u etsa liphetoho ho mefuta kapa limmapa tsa Sass, u tla hloka ho boloka liphetoho tsa hau le ho li bokella hape. Ho etsa joalo ho tla hlahisa sehlopha se secha sa litlelase tsa grid tse boletsoeng esale pele bakeng sa bophara ba likholomo, li-offsets le ho odara. Lisebelisoa tsa ponahalo tse arabelang le tsona li tla nchafatsoa ho sebelisa li-breakpoints tse tloaelehileng. Etsa bonnete ba hore o beha boleng ba grid ho px
(eseng rem
, em
, kapa %
).