I-Bootstrap yakhiwe kwigridi yekholamu ye-12 ephendulayo. Sikwaquke i-fixed- kunye ne-fluid-width layouts ngokusekelwe kuloo nkqubo.
I-Bootstrap isebenzisa izinto ze-HTML kunye neempawu zeCSS ezifuna ukusetyenziswa kwe-HTML5 doctype. Qiniseka ukuba uyayibandakanya ekuqaleni kwephepha ngalinye le-Bootstrapped kwiprojekthi yakho.
- <!DOCTYPE html>
- <html lang = "en" >
- ...
- </html>
Ngaphakathi kwefayile ye- scaffolding.less , siseta umboniso osisiseko wehlabathi, ukuchwetheza, kunye nezimbo zekhonkco. Ngokukodwa, thina:
background-color: white;
kwibody
@baseFontFamily
,, @baseFontSize
kunye @baseLineHeight
neempawu njengesiseko sethu sokuchwetheza@linkColor
kwaye usebenzise ikhonkco elikrwelelayo kuphela:hover
Ukususela kwi-Bootstrap 2, ukusetha ngokutsha kwe-CSS yemveli kuye kwavela ukuze kusetyenziswe izinto ezivela kwi- Normalize.css , iprojekthi kaNicolas Gallagher ekwanika amandla i- HTML5 Boilerplate .
Ukusetha ngokutsha okutsha kusenokufumaneka kwi- reset.less , kodwa ngezinto ezininzi ezisusiweyo ngenxa yobufutshane kunye nokuchaneka.
Inkqubo yegridi engagqibekanga enikwe kwiBootstrap isebenzisa iikholamu ezili -12 ezinikezela kububanzi obuyi-724px, 940px (ehlala ikho ngaphandle kwe-CSS ephendulayo ibandakanyiwe), kunye ne-1170px. Ngaphantsi kwe-767px yeendawo zokujonga, iikholamu ziba lulwelo kwaye zipakishwe ngokuthe nkqo.
- <div class = "umqolo" >
- <div class = "span4" > ... </div>
- <div class = "span8" > ... </div>
- </ div>
Njengoko kubonisiwe apha, uyilo olusisiseko lunokwenziwa “ngeekholamu” ezimbini, nganye ithatha inani leekholamu ezili-12 ezisisiseko esizichaze njengenxalenye yenkqubo yethu yegridi.
- <div class = "umqolo" >
- <div class = "span4" > ... </div>
- <div class = "span4 offset4" > ... </div>
- </ div>
Ngenkqubo yegridi engatshintshiyo (engeyiyo eyolwelo) kwiBootstrap, ukwenza indlwane kulula. Ukwakha umxholo wakho, yongeza nje entsha .row
kunye neseti yeekholamu ngaphakathi kwekholamu .span*
ekhoyo ..span*
Imiqolo ebekwe kwindlwane kufuneka ibandakanye uluhlu lwemiqolo edibanisa inani lemiqolo yomzali wayo. Umzekelo, .span3
iikholamu ezimbini ezifakwe kwindlwane kufuneka zibekwe ngaphakathi kwi- .span6
.
- <div class = "umqolo" >
- <div class = "span6" >
- Inqanaba loku-1 ikholamu
- <div class = "umqolo" >
- <div class = "span3" > Inqanaba lesi-2 </div>
- <div class = "span3" > Inqanaba lesi-2 </div>
- </ div>
- </ div>
- </ div>
Inkqubo yegridi yamanzi isebenzisa iipesenti kububanzi bekholomu endaweni yeepikseli ezisisigxina. Ikwanayo nokwahluka okuphendulayo okufanayo njengenkqubo yethu yegridi ezinzileyo, iqinisekisa ubungakanani obufanelekileyo bezisombululo eziphambili zesikrini kunye nezixhobo.
Yenza nawuphi na umqolo ube ulwelo ngokulula ngokutshintshela .row
ku- .row-fluid
. Iikholamu zihlala zifana ncakasana, nto leyo eyenza kube lula ukujika phakathi koyilo olusisigxina kunye nolwelo.
- <div class = "Row-fluid" >
- <div class = "span4" > ... </div>
- <div class = "span8" > ... </div>
- </ div>
Ukuzalela ngeegridi ezilulwelo kukwahluka kancinane: inani leentsika ezifakwe kwindlwane akuyomfuneko ukuba lihambelane nomzali. Endaweni yoko, iikholamu zakho zisetwa kwakhona kwinqanaba ngalinye kuba umqolo ngamnye uthatha i-100% yekholamu yomzali.
- <div class = "Row-fluid" >
- <div class = "span12" >
- Inqanaba loku-1 lekholamu
- <div class = "Row-fluid" >
- <div class = "span6" > Inqanaba lesi-2 </div>
- <div class = "span6" > Inqanaba lesi-2 </div>
- </ div>
- </ div>
- </ div>
Iyaguquguquka | Ixabiso elimiselweyo | Inkcazo |
---|---|---|
@gridColumns |
12 | Inani leekholamu |
@gridColumnWidth |
60px | Ububanzi bekholamu nganye |
@gridGutterWidth |
20px | Isithuba esibi phakathi kweekholamu |
Eyakhelwe kwiBootstrap zimbalwa zezinto eziguquguqukayo zokwenza ngokwezifiso inkqubo yegridi ye-940px, ebhalwe ngasentla. Zonke iinguqu zegridi zigcinwa kwi-variables.less.
Ukuguqula igridi kuthetha ukutshintsha izinto ezintathu @grid*
eziguquguqukayo kunye nokubuyisela kwakhona i-Bootstrap. Guqula igridi eguquguqukayo kwizinto eziguquguqukayo.ngaphantsi kwaye usebenzise enye yeendlela ezine ezibhaliweyo ukuqokelela kwakhona . Ukuba wongeza iikholamu ezininzi, qiniseka ukuba wongeza i-CSS kwabo bakwigridi.less.
Ukwenziwa ngokwezifiso kwegridi kusebenza kuphela kwinqanaba elimiselweyo, igridi ye-940px. Ukugcina imiba ephendulayo ye-Bootstrap, kuya kufuneka ukuba wenze ngokwezifiso iigridi kwi-responsive.less.
Uyilo olungagqibekanga kunye olulula lwe-940px-ebanzi, oluphakathi nendawo malunga nayo nayiphi na iwebhusayithi okanye iphepha elinikezelweyo <div class="container">
.
- <umzimba>
- <div class = "container" >
- ...
- </ div>
- </ umzimba>
<div class="container-fluid">
inika ulwakhiwo lwephepha oluguquguqukayo, min- kunye nobubanzi obukhulu, kunye nebar yecala lasekhohlo. Ilungile kusetyenziso kunye namaxwebhu.
- <div class = "container-fluid" >
- <div class = "Row-fluid" >
- <div class = "span2" >
- <!--Umxholo wesixwexwe esisecaleni-->
- </ div>
- <div class = "span10" >
- <!--Umxholo womzimba-->
- </ div>
- </ div>
- </ div>
Imibuzo yemidiya ivumela i-CSS yesiko ngokusekelwe kwinani leemeko-imilinganiselo, ububanzi, uhlobo lokubonisa, njl njl-kodwa ngokuqhelekileyo kugxininise min-width
kwaye max-width
.
Sebenzisa imibuzo yemidiya ngokuthembekileyo kwaye kuphela njengesiqalo kubaphulaphuli bakho beselula. Kwiiprojekthi ezinkulu, qwalasela iziseko zekhowudi ezinikezelweyo kwaye hayi iileyibhile zemibuzo yemidiya.
I-Bootstrap ixhasa iqela lemibuzo yemidiya kwifayile enye ukunceda ukwenza iiprojekthi zakho zifaneleke ngakumbi kwizixhobo ezahlukeneyo kunye nezisombululo zesikrini. Nantsi into ebandakanyiweyo:
Ileyibhile | Ububanzi bobeko | Ububanzi bekholamu | Ububanzi bomsele |
---|---|---|---|
Ii-smartphones | 480px nangaphantsi | Iikholamu zolwelo, akukho bubanzi busisigxina | |
Ii-smartphones kwiitafile | 767px nangaphantsi | Iikholamu zolwelo, akukho bubanzi busisigxina | |
Portrait tablets | 768px nangaphezulu | 42px | 20px |
Ukuhlala kukho | 980px kwaye phezulu | 60px | 20px |
Umboniso omkhulu | 1200px nangaphezulu | 70px | 30px |
Ukuqinisekisa ukuba izixhobo zibonakalisa amaphepha aphendulayo ngokufanelekileyo, quka i-meta tag ye-viewport.
- <meta name = "viewport" content = "width=device-width, first-scale=1.0" >
I-Bootstrap ayibandakanyi ngokuzenzekelayo le mibuzo yemidiya, kodwa ukuqonda kunye nokuzongeza kulula kakhulu kwaye kufuna ukuseta okuncinci. Unokukhetha okumbalwa kokubandakanya iimpawu eziphendulayo zeBootstrap:
Kutheni ungayifaki nje? Inyaniso mayithethwe, ayizizo zonke izinto ezifuna ukuphendulwa. Endaweni yokukhuthaza abaphuhlisi ukuba balisuse eli nqaku, sibona ukuba yeyona nto ilungileyo ukuyenza.
- /* Iifowuni zokujonga umhlaba kunye nezantsi */
- @media ( max - wide : 480px ) { ... }
- /* Ifowuni yokujonga umhlaba kwithebhulethi yokubonisa */
- @media ( max - wide : 767px ) { ... }
- /* Umfanekiso wethebhulethi kwimbonakalo yomhlaba kunye nedesktop */
- @media ( min - ububanzi : 768px ) kunye ( max - ububanzi : 979px ) { ... }
- /* Idesktop enkulu */
- @media ( min - ububanzi : 1200px ) { ... }
Kuphuhliso olukhawulezayo lweselula, sebenzisa ezi klasi ziluncedo zokubonisa kunye nokufihla umxholo ngesixhobo.
Sebenzisa ngokulinganiselweyo kwaye ugweme ukwenza iinguqulelo ezahlukeneyo ngokupheleleyo kwindawo enye. Endaweni yoko, zisebenzise ukuncedisana neprizenteyishini yesixhobo ngasinye.
Umzekelo, ungabonisa i <select>
element ye nav kuyilo lwemobile, kodwa hayi kwiitafile okanye iidesktop.
Iboniswe apha yitheyibhile yeeklasi esizixhasayo kunye nesiphumo sazo kuyilo lombuzo wemidiya enikiweyo (ebhalwe ngesixhobo). Zinokufumaneka kwi responsive.less
.
Iklasi | Iifowuni480px nangaphantsi | Amacwecwe767px nangaphantsi | Iideskithophu768px nangaphezulu |
---|---|---|---|
.visible-phone |
Iyabonakala | Ifihliwe | Ifihliwe |
.visible-tablet |
Ifihliwe | Iyabonakala | Ifihliwe |
.visible-desktop |
Ifihliwe | Ifihliwe | Iyabonakala |
.hidden-phone |
Ifihliwe | Iyabonakala | Iyabonakala |
.hidden-tablet |
Iyabonakala | Ifihliwe | Iyabonakala |
.hidden-desktop |
Iyabonakala | Iyabonakala | Ifihliwe |
Yenza ubungakanani kwakhona kwisikhangeli sakho okanye ulayishe kwizixhobo ezahlukeneyo ukuvavanya ezi klasi zingentla.
Iimpawu eziluhlaza zibonisa ukuba iklasi iyabonakala kwindawo yakho yokujonga yangoku.
Apha, amanqaku okukhangela aluhlaza abonisa ukuba udidi lufihliwe kwindawo yakho yokujonga yangoku.