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.
Kamoo e sebetsang kateng
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 .
Likhetho tsa grid
Leha Bootstrap e sebelisa em
s kapa rem
s 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 |
Likholomo tsa moralo oa boiketsetso
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
.
Bophara bo lekanang
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.
E lekanang-bophara ba mela e mengata
Etsa likholomo tse bophara bo lekanang tse nang le mela e mengata ka ho kenya .w-100
moo u batlang hore litšiea li khaohe ho ea moleng o mocha. Etsa hore khefu e sebetse ka ho kopanya .w-100
le lisebelisoa tse ling tse arabelang .
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 mefuta ea khale ea sebatli, empa ha ea lokela ho hlokahala haeba libatli tseo u li batlang li sa oele mefuteng ea buggy.
Ho beha bophara ba kholomo e le 'ngoe
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.
Likahare tse fapaneng tsa bophara
Sebelisa col-{breakpoint}-auto
litlelase ho isa likholomong tsa boholo ho ipapisitsoe le bophara ba tlhaho ba litaba tsa tsona.
Lihlopha 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.
Li-breakpoints tsohle
Bakeng sa marang-rang a ts'oanang ho tloha ho lisebelisoa tse nyane ho isa ho tse kholo, sebelisa .col
le .col-*
lihlopha. Hlalosa sehlopha sa linomoro ha u hloka kholomo e boholo bo khethehileng; ho seng joalo, ikutloe u lokolohile ho khomarela .col
.
E khomaretsoe ho ea holimo
U sebelisa sehlopha se le seng sa .col-sm-*
litlelase, u ka theha sistimi ea grid e qalang e phuthetsoe ebe e ba e tšekaletseng sebakeng se senyenyane ( sm
).
Kopanya le ho bapisa
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.
Lithako
Li-Gutters li ka fetoloa ka mokhoa o ts'oanelang ka li-padding tse ikhethileng le litlelase tse mpe tsa tšebeliso ea marang-rang. Ho fetola li-gutters ka tatellano e fanoeng, kopanya ts'ebeliso e mpe ea marang-rang holim'a lisebelisoa .row
tse tšoanang tsa padding ho .col
s. Ho ka 'na ha hlokahala hore motsoali .container
kapa .container-fluid
motsoali a lokisoe ho qoba ho phalla ho sa batleheng, a sebelisa lisebelisoa tse tšoanang hape.
Mohlala ke ona oa ho etsa grid ea Bootstrap sebakeng se seholo ( lg
) le holimo. Re ekelitse .col
padding ka .px-lg-5
, ra hanana le seo .mx-lg-n5
ho motsoali .row
mme .container
ra lokisa sephutheloana ka .px-lg-5
.
Litšiea tsa mela
Sebelisa .row-cols-*
litlelase tse arabelang ho beha kapele palo ea likholomo tse fanang ka litaba tsa hau hantle le sebopeho. Le hoja litlelase tse tloaelehileng .col-*
li sebetsa ho likholomo ka bomong (mohlala, .col-md-4
), litlelase tsa mela e behiloe ho motsoali .row
joalo ka tsela e khaoletsang.
Sebelisa litlelase tsena tsa mela ho theha meralo ea grid ea mantlha ka potlako kapa ho laola meralo ea likarete tsa hau.
U ka sebelisa motsoako o tsamaeang le Sass, row-cols()
:
Ho tsamaisana
Sebelisa lisebelisoa tsa tekano ea flexbox ho hokahanya likholomo tse otlolohileng le tse tšekaletseng. Internet Explorer 10-11 ha e tšehetse tokiso e otlolohileng ea lintho tse feto-fetohang ha sesebelisoa sa flex se na le min-height
joalo ka ha ho bonts'itsoe ka tlase. Sheba Flexbugs #3 bakeng sa lintlha tse ling.
Tsepamiso e otlolohileng
Ho tsamaisana le maemo
Ha ho li-gutters
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 shebisitsoe 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).
Ho phuthela khola
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.
Likhefutso tsa khola
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 .
Ho hlophisa bocha
Odara lihlopha
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.
Litšiea tsa offsetting
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 na le thuso bakeng sa meralo e potlakileng moo bophara ba offset bo fetohang.
Lihlopha tsa Offset
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 .
Lisebelisoa tsa 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.
Nesting
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).
Sass metsoako
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.
Mefuta e fapaneng
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.
Metsoako
Li-mixins li sebelisoa hammoho le mefuta e fapaneng ea grid ho hlahisa CSS ea semantic bakeng sa likholomo tsa grid ka bomong.
Tšebeliso ea mohlala
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.
Ho iketsetsa grid
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.
Litšiea le li-gutters
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.
Lihlopha tsa grid
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 %
).