Bootstrap e hahiloe holim'a marang-rang a 12-kholomo e arabelang. Hape re kenyelelitse meralo e tsitsitseng le bophara ba metsi ho latela sistimi eo.
Bootstrap e sebelisa likarolo tsa HTML le thepa ea CSS e hlokang ts'ebeliso ea HTML5 doctype. Etsa bonnete ba hore o e kenyelletsa qalong ea leqephe le leng le le leng la Bootstrapped morerong oa hau.
- <!DOCTYPE html>
- <html lang = "en" >
- ...
- </html>
Ka har'a faele ea scaffolding.less , re theha ponts'o ea lefats'e, typography, le mekhoa ea likhokahanyo. Ka ho khetheha, re:
background-color: white;
holim'abody
@baseFontFamily
, @baseFontSize
, le @baseLineHeight
litšoaneleho e le motheo oa typography ea rona@linkColor
ho sebelisa mehala ea likhokahano feela ho eona:hover
Ho tloha ka Bootstrap 2, ho seta bocha CSS ho fetohile ho sebelisa likarolo ho tsoa ho Normalize.css , morero oa Nicolas Gallagher o matlafatsang HTML5 Boilerplate .
Reset e ncha e ntse e ka fumaneha ho reset.less , empa ka likarolo tse ngata tse tlositsoeng bakeng sa bokhutšoanyane le ho nepahala.
Sistimi ea grid ea kamehla e fanoeng Bootstrap e sebelisa likholomo tse 12 tse fanang ka bophara ba 724px, 940px (kamehla ntle le ho kenyeletsoa CSS e arabelang), le 1170px. Ka tlas'a 767px li-viewports, litšiea li fetoha metsi 'me li tsitsa ho ea holimo.
- <div class = "row" >
- <div class = "span4" > ... </div>
- <div class = "span8" > ... </div>
- </ div>
Joalo ka ha ho bonts'itsoe mona, moralo oa mantlha o ka etsoa ka "likholomo" tse peli, e 'ngoe le e 'ngoe e nka palo ea litšiea tse 12 tseo re li hlalositseng e le karolo ea sistimi ea rona.
- <div class = "row" >
- <div class = "span4" > ... </div>
- <div class = "span4 offset4" > ... </div>
- </ div>
Ka sistimi e tsitsitseng (e seng mokelikeli) ho Bootstrap, ho haha sehlaha ho bonolo. Ho hlophisa litaba tsa hau, kenya feela likholomo tse ncha .row
ka .span*
har'a .span*
kholomo e teng.
Mela e hlophiloeng e tlameha ho kenyelletsa sehlopha sa likholomo tse kopanyang palo ea likholomo tsa motsoali oa eona. Ka mohlala, .span3
litšiea tse peli tse behiloeng li lokela ho behoa ka har'a .span6
.
- <div class = "row" >
- <div class = "span6" >
- Karolo ea 1
- <div class = "row" >
- <div class = "span3" > Mohato 2 </div>
- <div class = "span3" > Mohato 2 </div>
- </ div>
- </ div>
- </ div>
Sistimi ea grid ea mokelikeli e sebelisa lipersente bakeng sa bophara ba likholomo ho fapana le lipikselse tse tsitsitseng. E boetse e na le mefuta e fapaneng e arabelang joalo ka sistimi ea rona e tsitsitseng ea grid, e netefatsang likarolo tse nepahetseng bakeng sa liqeto tsa bohlokoa tsa skrineng le lisebelisoa.
Etsa mokelikeli ofe kapa ofe ka ho fetola .row
ho .row-fluid
. Litšiea li lula li tšoana hantle, e leng ho etsang hore ho be bonolo haholo ho pota-pota pakeng tsa libopeho tse tsitsitseng le tse nang le metsi.
- <div class = "row-fluid" >
- <div class = "span4" > ... </div>
- <div class = "span8" > ... </div>
- </ div>
Ho haha sehlaha ka li-grids tsa mokelikeli ho batla ho fapane: palo ea litšiea ha e hloke ho ts'oana le motsoali. Sebakeng seo, litšiea tsa hau li setiloe bocha boemong bo bong le bo bong hobane mola o mong le o mong o nka 100% ea kholomo ea motsoali.
- <div class = "row-fluid" >
- <div class = "span12" >
- Boemo ba 1 ba kholomo
- <div class = "row-fluid" >
- <div class = "span6" > Mohato 2 </div>
- <div class = "span6" > Mohato 2 </div>
- </ div>
- </ div>
- </ div>
E fetohang | Boleng ba kamehla | Tlhaloso |
---|---|---|
@gridColumns |
12 | Palo ea litšiea |
@gridColumnWidth |
60px | Bophara ba kholomo ka 'ngoe |
@gridGutterWidth |
20px | Sebaka se fosahetseng pakeng tsa litšiea |
E hahiloe ka har'a Bootstrap ho na le mefuta e mengata e fapaneng bakeng sa ho etsa sistimi ea grid ea 940px, e ngotsoeng ka holimo. Mefuta eohle ea marang-rang e bolokoa ka mefuta-futa.nya.
Ho fetola grid ho bolela ho fetola @grid*
mefuta e meraro le ho khutlisetsa Bootstrap. Fetola li-grid tse feto-fetohang ka ho feto-fetoha.e fokolang 'me u sebelise e' ngoe ea litsela tse 'nè tse ngotsoeng ho bokella hape . Haeba u eketsa litšiea tse ling, etsa bonnete ba hore u kenya CSS bakeng sa ba leng grid.less.
Ho ikamahanya ha grid ho sebetsa feela maemong a kamehla, grid ea 940px. Ho boloka likarolo tse arabelang tsa Bootstrap, u tla tlameha hape ho hlophisa li-grid ka mokhoa o arabelang.less.
Sebopeho sa kamehla le se bonolo sa 940px-wide, se bohareng bakeng sa sebaka sa marang-rang sefe kapa sefe kapa leqephe le fanoeng ke <div class="container">
.
- <'mele>
- <div class = "setshelo" >
- ...
- </ div>
- </ mmele>
<div class="container-fluid">
e fana ka sebopeho sa leqephe se feto-fetohang, bophara ba min- le max-widths, le karolo e ka letsohong le letšehali. E ntle bakeng sa lisebelisoa le litokomane.
- <div class = "container-fluid" >
- <div class = "row-fluid" >
- <div class = "span2" >
- <!--Likahare tsa Sidebar-->
- </ div>
- <div class = "span10" >
- <!--Dikahare tsa mmele-->
- </ div>
- </ div>
- </ div>
Lipotso tsa mecha ea litaba li lumella CSS e tloaelehileng ho latela maemo a 'maloa-karolelano, bophara, mofuta oa pontšo, joalo-joalo-empa hangata e lebisa tlhokomelo ho pota-pota min-width
le max-width
.
Sebelisa lipotso tsa media ka mokhoa o nang le boikarabelo ebile e le qalo feela ho bamameli ba hau ba mehala. Bakeng sa merero e meholoanyane, nahana ka li-code tse inehetseng eseng likarolo tsa lipotso tsa media.
Bootstrap e ts'ehetsa lipotso tse 'maloa tsa media faeleng e le' ngoe ho thusa ho etsa hore merero ea hau e be e loketseng lisebelisoa tse fapaneng le liqeto tsa skrineng. Mona ke tse kenyellelitsoeng:
Label | Bophara ba sebopeho | Bophara ba kholomo | Bophara ba sekoti |
---|---|---|---|
Li-smartphone | 480px le ka tlase | Litšiea tsa metsi, ha ho bophara bo tsitsitseng | |
Li-smartphone ho matlapa | 767px le ka tlase | Litšiea tsa metsi, ha ho bophara bo tsitsitseng | |
Matlapa a setšoantšo | 768px le holimo | 42px | 20px |
Ea kamehla | 980px ho ea holimo | 60px | 20px |
Pontšo e kholo | 1200px ho ea holimo | 70px | 30px |
Ho etsa bonnete ba hore lisebelisoa li bonts'a maqephe a arabelang hantle, kenyelletsa le "viewport meta tag".
- <meta name = "viewport" content = "width=sesebediswa-bophara, sekala sa ho qala=1.0" >
Bootstrap ha e kenyelle lipotso tsena tsa media ka bo eona, empa ho li utloisisa le ho li eketsa ho bonolo haholo mme ho hloka ho seta ho fokolang. U na le likhetho tse 'maloa tsa ho kenyelletsa likarolo tse arabelang tsa Bootstrap:
Ke hobane'ng ha u sa e kenyelle feela? Ha e le hantle, ha se ntho e 'ngoe le e' ngoe e lokelang ho etsoa. Sebakeng sa ho khothaletsa baetsi ho tlosa tšobotsi ena, re bona ho le molemo ho e nolofalletsa.
- /* Mehala ea naha le tlase */
- @media ( max - wide : 480px ) { ... }
- /* Fono ea sebopeho sa naha ho ea ho letlapa la litšoantšo */
- @media ( max - wide : 767px ) { ... }
- /* Letlapa la litšoantšo ho sebopeho sa naha le komporo */
- @media ( min - width : 768px ) le ( max - width : 979px ) { ... }
- /* desktop e kholo */
- @media ( min - width : 1200px ) { ... }
Bakeng sa nts'etsopele e potlakileng ea ho sebelisa mehala, sebelisa litlelase tsena tsa mantlha tsa lisebelisoa ho bonts'a le ho pata litaba ka sesebelisoa.
Sebelisa ka mokhoa o fokolang 'me u qobe ho theha mefuta e fapaneng ka ho felletseng ea sebaka se le seng. Ho e-na le hoo, li sebelise ho tlatselletsa tlhahiso ea sesebelisoa ka seng.
Mohlala, o kanna oa bonts'a <select>
element bakeng sa nav lits'ebetsong tsa mehala, empa eseng matlapeng kapa li-desktops.
Mona ho bonts'itsoe lethathamo la lihlopha tseo re li tšehetsang le phello ea tsona ho sebopeho sa potso ea media (e ngotsoeng ka sesebelisoa). Li ka fumanoa ho responsive.less
.
Sehlopha | Mehala480px le ka tlase | Matlapa767px le ka tlase | Lisebelisoa tsa desktop768px le holimo |
---|---|---|---|
.visible-phone |
Tse bonahalang | E patiloe | E patiloe |
.visible-tablet |
E patiloe | Tse bonahalang | E patiloe |
.visible-desktop |
E patiloe | E patiloe | Tse bonahalang |
.hidden-phone |
E patiloe | Tse bonahalang | Tse bonahalang |
.hidden-tablet |
Tse bonahalang | E patiloe | Tse bonahalang |
.hidden-desktop |
Tse bonahalang | Tse bonahalang | E patiloe |
Fetola boholo ba sebatli sa hau kapa kenya lisebelisoa tse fapaneng ho leka lihlopha tse kaholimo.
Matšoao a matala a bontša hore sehlopha sea bonahala sebakeng sa hau sa pono sa hajoale.
Mona, matšoao a matala a bonts'a hore sehlopha se patiloe sebakeng sa hau sa pono sa hajoale.