Bootstrap yog tsim los ntawm kev teb 12-kab kab sib chaws. Peb kuj tau suav nrog cov txheej txheem ruaj khov- thiab cov dej dav dav raws li qhov system ntawd.
Bootstrap ua rau siv cov ntsiab lus HTML thiab CSS cov khoom uas yuav tsum tau siv cov HTML5 doctype. Nco ntsoov suav nrog nws thaum pib ntawm txhua nplooj ntawv Bootstrapped hauv koj qhov project.
- <!DOCTYPE html>
- <html lang = "en" >
- ...
- </html>
Nyob rau hauv cov ntaub ntawv scaffolding.less , peb teeb tsa lub ntiaj teb cov zaub yooj yim, typography, thiab txuas cov qauv. Tshwj xeeb, peb:
background-color: white;
rau ntawmbody
@baseFontFamily
, @baseFontSize
, thiab @baseLineHeight
cov cwj pwm ua peb lub hauv paus typography@linkColor
thiab siv qhov txuas hauv qab tsuas yog rau:hover
Raws li ntawm Bootstrap 2, ib txwm CSS rov pib dua tau hloov zuj zus los ua kom siv cov ntsiab lus los ntawm Normalize.css , ib txoj haujlwm los ntawm Nicolas Gallagher uas tseem ua haujlwm rau HTML5 Boilerplate .
Qhov kev rov pib dua tshiab tseem tuaj yeem pom hauv reset.less , tab sis nrog ntau lub ntsiab lus tshem tawm rau brevity thiab raug.
Lub default grid system muab hauv Bootstrap siv 12 kab uas ua tawm ntawm qhov dav ntawm 724px, 940px (default tsis teb CSS suav nrog), thiab 1170px. Hauv qab 767px viewports, cov kab ua kua thiab pawg vertically.
- <div class = "row" >
- <div class = "span4" > ... </div>
- <div class = "span8" > ... </div>
- </div>
Raws li pom ntawm no, ib qho kev teeb tsa yooj yim tuaj yeem tsim nrog ob "kab", txhua qhov txuas ntxiv ntawm 12 lub hauv paus kab peb txhais tau tias yog ib feem ntawm peb cov kab sib chaws.
- <div class = "row" >
- <div class = "span4" > ... </div>
- <div class = "span4 offset4" > ... </div>
- </div>
Nrog rau qhov zoo li qub (tsis yog kua) kab sib chaws hauv Bootstrap, nesting yog ib qho yooj yim. Txhawm rau zes koj cov ntsiab lus, tsuas yog ntxiv ib qho tshiab .row
thiab cov .span*
kab ke hauv ib .span*
kab uas twb muaj lawm.
Nested kab yuav tsum suav nrog ib pawg kab uas ntxiv mus rau cov kab ntawm nws niam nws txiv. Piv txwv li, ob kab nested .span3
yuav tsum muab tso rau hauv ib lub .span6
.
- <div class = "row" >
- <div class = "span6" >
- Qib 1 kab
- <div class = "row" >
- <div class = "span3" > Qib 2 </div>
- <div class = "span3" > Qib 2 </div>
- </div>
- </div>
- </div>
Cov kab sib chaws dej siv feem pua rau kab dav dav tsis yog cov pixels ruaj khov. Nws kuj tseem muaj cov kev hloov pauv zoo ib yam li peb cov kab sib txuas ruaj khov, ua kom muaj qhov sib luag zoo rau cov kev daws teeb meem tseem ceeb thiab cov khoom siv.
Ua tej kab dej yooj yim los ntawm kev hloov .row
mus rau .row-fluid
. Cov kab ntawv nyob twj ywm tib yam nkaus, ua rau nws yooj yim heev kom tig ntawm qhov chaw ruaj khov thiab cov kua dej.
- <div class = "row-fluid" >
- <div class = "span4" > ... </div>
- <div class = "span8" > ... </div>
- </div>
Kev ua zes nrog cov kua dej sib txawv me ntsis: tus naj npawb ntawm cov kab nested tsis tas yuav phim tus niam txiv. Hloov chaw, koj cov kab rov pib dua ntawm txhua qib vim tias txhua kab yuav siv 100% ntawm niam txiv kab.
- <div class = "row-fluid" >
- <div class = "span12" >
- Qib 1 ntawm kab
- <div class = "row-fluid" >
- <div class = "span6" > Qib 2 </div>
- <div class = "span6" > Qib 2 </div>
- </div>
- </div>
- </div>
Hloov pauv | Default tus nqi | Kev piav qhia |
---|---|---|
@gridColumns |
12 | Tus naj npawb ntawm kab |
@gridColumnWidth |
60 px | Dav ntawm txhua kab |
@gridGutterWidth |
20px ib | Qhov chaw tsis zoo ntawm kab |
Ua rau hauv Bootstrap yog ib txhais tes ntawm qhov sib txawv rau kev kho lub neej ntawd 940px kab sib chaws, sau tseg saum toj no. Txhua qhov hloov pauv rau daim phiaj yog khaws cia hauv variables.less.
Hloov kho daim phiaj txhais tau tias hloov peb @grid*
qhov sib txawv thiab rov ua dua Bootstrap. Hloov cov kab sib chaws sib txawv hauv variables.less thiab siv ib qho ntawm plaub txoj hauv kev sau tseg los ua kom rov ua dua . Yog tias koj ntxiv cov kab ntau ntxiv, nco ntsoov ntxiv CSS rau cov hauv grid.less.
Customization ntawm daim phiaj tsuas yog ua haujlwm ntawm theem pib, 940px daim phiaj. Txhawm rau tuav cov lus teb ntawm Bootstrap, koj tseem yuav tau kho cov phiaj xwm hauv responsive.less.
Lub neej ntawd thiab yooj yim 940px-dav, nruab nrab layout rau ib lub vev xaib lossis nplooj ntawv muab los ntawm ib leeg <div class="container">
.
- <lub cev>
- <div class = "container" >
- ...
- </div>
- </body>
<div class="container-fluid">
muab cov nplooj ntawv hloov tau yooj yim, min- thiab max-widths, thiab sab laug-tes sab. Nws yog qhov zoo rau apps thiab docs.
- <div class = "container-fluid" >
- <div class = "row-fluid" >
- <div class = "span2" >
- <!--Sidebar cov ntsiab lus-->
- </div>
- <div class = "span10" >
- <!-- Lub cev ntsiab lus-->
- </div>
- </div>
- </div>
Media queries tso cai rau kev cai CSS raws li ib tug xov tooj ntawm tej yam kev mob - piv txwv, dav, hom zaub, thiab lwm yam - tab sis feem ntau tsom ib ncig min-width
thiab max-width
.
Siv cov lus nug xov xwm muaj lub luag haujlwm thiab tsuas yog pib rau koj cov neeg tuaj saib hauv xov tooj. Rau cov haujlwm loj dua, xav txog cov txheej txheem tshwj xeeb thiab tsis yog txheej txheej ntawm cov lus nug xov xwm.
Bootstrap txhawb nqa ib txhais tes ntawm cov lus nug xov xwm hauv ib cov ntaub ntawv los pab ua kom koj cov haujlwm tsim nyog ntawm cov khoom siv sib txawv thiab kev tshuaj ntsuam. Nov yog yam uas suav nrog:
Daim ntawv lo | Layout dav | Kab dav | Gutter dav |
---|---|---|---|
Smartphones | 480px e ua | Cov kab dej ntws, tsis muaj qhov dav ruaj khov | |
Smartphones rau ntsiav tshuaj | 767px ,ua | Cov kab dej ntws, tsis muaj qhov dav ruaj khov | |
Portrait ntsiav tshuaj | 7 68px ,ua | 4 2px | 20px ib |
Default | 9 80px | 60 px | 20px ib |
Loj zaub | 1200px thiab siab dua | 70px ib | 30px ib |
Txhawm rau kom cov cuab yeej tso saib cov nplooj ntawv teb kom raug, suav nrog cov cim npe pom.
- <meta name = "viewport" cov ntsiab lus = "width=device-width, pib-scale=1.0" >
Bootstrap tsis cia li suav nrog cov lus nug xov xwm no, tab sis kev nkag siab thiab ntxiv lawv yog qhov yooj yim heev thiab yuav tsum tau teeb tsa tsawg. Koj muaj ob peb txoj kev xaiv rau suav nrog cov lus teb ntawm Bootstrap:
Vim li cas ho tsis suav nrog nws? Qhia tseeb, tsis yog txhua yam yuav tsum tau teb. Es tsis txhob txhawb cov neeg tsim tawm kom tshem tawm cov yam ntxwv no, peb xav tias nws zoo tshaj los pab nws.
- /* Toj roob hauv pes xov tooj thiab nqes */
- @media ( max - dav : 480px ) { ... }
- /* Toj roob hauv pes xov tooj rau portrait ntsiav tshuaj */
- @media ( max - dav : 767px ) { ... }
- /* Portrait ntsiav tshuaj rau toj roob hauv pes thiab desktop */
- @media ( min - dav : 768px ) thiab ( max - dav : 979px ) { ... }
- /* Loj desktop */
- @media ( min - dav : 1200px ) { ... }
Rau kev txhim kho mobile-phooj ywg sai dua, siv cov chav kawm siv hluav taws xob yooj yim no los qhia thiab zais cov ntsiab lus los ntawm lub cuab yeej.
Siv raws li kev txwv thiab zam kev tsim cov qauv sib txawv ntawm tib lub xaib. Hloov chaw, siv lawv los ntxiv rau txhua lub cuab yeej kev nthuav qhia.
Piv txwv li, tej zaum koj yuav qhia ib lub <select>
ntsiab rau nav ntawm mobile layouts, tab sis tsis nyob rau hauv cov ntsiav tshuaj los yog desktops.
Qhia ntawm no yog lub rooj ntawm cov chav kawm uas peb txhawb nqa thiab lawv cov txiaj ntsig ntawm cov lus nug xov xwm layout (labeled los ntawm ntaus ntawv). Lawv tuaj yeem pom hauv responsive.less
.
Chav kawm | Xov tooj480px e ua | Cov ntsiav tshuaj767px ,ua | Desktops7 68px ,ua |
---|---|---|---|
.visible-phone |
Pom tau | zais | zais |
.visible-tablet |
zais | Pom tau | zais |
.visible-desktop |
zais | zais | Pom tau |
.hidden-phone |
zais | Pom tau | Pom tau |
.hidden-tablet |
Pom tau | zais | Pom tau |
.hidden-desktop |
Pom tau | Pom tau | zais |
Resize koj tus browser lossis thauj khoom ntawm cov khoom siv sib txawv los kuaj cov chav kawm saum toj no.
Green checkmarks qhia tias chav kawm pom hauv koj qhov chaw saib tam sim no.
Ntawm no, ntsuab checkmarks qhia tias chav kawm tau muab zais rau hauv koj qhov chaw saib tam sim no.