Daim phiaj system
Siv peb lub zog mobile-thawj flexbox kab sib chaws los tsim cov layouts ntawm tag nrho cov duab thiab qhov ntau thiab tsawg ua tsaug rau kaum ob kem system, tsib lub ntsiab lus teb tiers, Sass variables thiab mixins, thiab kaum ob chav kawm ua ntej.
Nws ua haujlwm li cas
Bootstrap's grid system siv cov thawv ntim, kab, thiab txhua kab los tsim thiab kho cov ntsiab lus. Nws tau tsim nrog flexbox thiab muaj kev ua haujlwm siab. Hauv qab no yog ib qho piv txwv thiab qhov tob saib seb cov kab sib chaws tuaj ua ke li cas.
Tshiab los yog tsis paub nrog flexbox? Nyeem qhov CSS Tricks flexbox phau ntawv qhia rau keeb kwm yav dhau, cov ntsiab lus, cov lus qhia, thiab cov lej snippets.
Cov piv txwv saum toj no tsim peb kab vaj huam sib luag ntawm cov khoom me me, nruab nrab, loj, thiab cov khoom siv loj ntxiv uas siv peb cov chav kawm ntawv teev tseg ua ntej. Cov kab ntawv no yog nyob nruab nrab ntawm nplooj ntawv nrog niam txiv .container
.
Ua txhaum nws, ntawm no yog qhov nws ua haujlwm:
- Ntim muab ib txoj hauv kev rau nruab nrab thiab kab rov tav pad koj qhov chaw cov ntsiab lus. Siv
.container
rau lub teb pixel dav lossis.container-fluid
rauwidth: 100%
thoob plaws txhua qhov chaw saib thiab qhov ntau thiab tsawg. - Kab yog wrappers rau kab. Txhua kem muaj kab rov tav
padding
(hu ua gutter) rau tswj qhov chaw nruab nrab ntawm lawv. Qhov nopadding
yog ces counteracted ntawm kab nrog tsis zoo margins. Ua li no, tag nrho cov ntsiab lus hauv koj cov kab ntawv yog visually dlhos sab laug. - Nyob rau hauv ib daim phiaj layout, cov ntsiab lus yuav tsum muab tso rau hauv txhua kab thiab tsuas yog kab yuav yog cov me nyuam tam sim ntawm kab.
- Ua tsaug rau flexbox, daim phiaj kab uas tsis muaj qhov tshwj xeeb
width
yuav cia li layout raws li cov kab sib npaug. Piv txwv li, plaub lub sij hawm ntawm.col-sm
txhua tus yuav tau txais 25% dav ntawm qhov me me thiab nce. Saib cov kab ke auto-layout rau cov piv txwv ntxiv. - Cov chav kawm kab qhia cov kab uas koj xav siv tawm ntawm qhov ua tau 12 ib kab. Yog li, yog tias koj xav tau peb kab sib npaug-dav thoob plaws, koj tuaj yeem siv
.col-4
. - Kem
width
s tau teeb tsa hauv feem pua, yog li lawv ib txwm muaj dej thiab qhov loj me ntawm lawv cov niam txiv keeb kwm. - Cov kab muaj kab rov tav
padding
los tsim cov gutters ntawm cov kab ke, txawm li cas los xij, koj tuaj yeem tshem tawmmargin
ntawm kab thiabpadding
los ntawm kab nrog.no-gutters
rau ntawm.row
. - Txhawm rau ua kom cov kab sib txuas lus, muaj tsib daim phiaj tawg, ib qho rau txhua qhov kev cuam tshuam : tag nrho cov breakpoints (ntxiv me), me, nruab nrab, loj, thiab loj ntxiv.
- Grid breakpoints yog raws li qhov tsawg kawg nkaus qhov dav tshaj tawm cov lus nug, txhais tau tias lawv siv rau qhov ntawd ib qho kev tawg thiab tag nrho cov saum toj no (xws li,
.col-sm-4
siv rau cov khoom me me, nruab nrab, loj, thiab cov khoom loj ntxiv, tab sis tsis yog thawj qhovxs
kev tawg). - Koj tuaj yeem siv cov chav kawm ntawv uas tau hais tseg ua ntej (xws li
.col-4
) lossis Sass mixins rau ntau qhov cim cim.
Paub txog cov kev txwv thiab kab nyob ib ncig ntawm flexbox , zoo li qhov tsis muaj peev xwm siv qee cov ntsiab lus HTML li flex ntim .
Grid xaiv
Thaum Bootstrap siv em
s lossis rem
s rau kev txhais ntau qhov ntau thiab tsawg, px
s yog siv rau cov phiaj xwm tawg thiab cov thawv dav. Qhov no yog vim qhov dav ntawm qhov chaw saib yog nyob rau hauv pixels thiab tsis hloov nrog font loj .
Saib seb yam ntawm Bootstrap grid system ua haujlwm li cas hla ntau yam khoom siv nrog lub rooj ua ke.
Ntxiv me me <576px |
Me me ≥576px |
Nruab nrab ≥768px |
Loj ≥992px |
Ntxiv loj ≥1200px |
|
---|---|---|---|---|---|
Max thawv dav | Tsis muaj (auto) | 5 40px | 7 20px | 9 60px | 1 140px |
Chav ua ntej | .col- |
.col-sm- |
.col-md- |
.col-lg- |
.col-xl- |
# ntawm kab | 12 | ||||
Gutter dav | 30px (15px ntawm txhua sab ntawm kab) | ||||
Nestable | Yog lawm | ||||
Kem xaj | Yog lawm |
Auto-layout kab
Siv cov chav kawm tshwj xeeb ntawm cov kab ke tshwj xeeb kom yooj yim kem qhov loj me yam tsis muaj cov lej qhia meej xws li .col-sm-6
.
Sib npaug-dav
Piv txwv li, ntawm no yog ob daim phiaj layouts uas siv rau txhua lub cuab yeej thiab qhov chaw saib, los ntawm xs
mus rau xl
. Ntxiv ib chav tsev-tsawg chav kawm rau txhua qhov breakpoint koj xav tau thiab txhua kab yuav yog tib qhov dav.
Sib npaug-dav ntau kab
Tsim cov kab sib npaug-dav uas hla ntau kab los ntawm kev ntxig ib .w-100
qhov chaw koj xav kom cov kab tawg mus rau kab tshiab. Ua kom tawg teb los ntawm kev sib xyaw .w-100
nrog qee cov khoom siv hluav taws xob teb .
Muaj Safari flexbox kab laum uas tiv thaiv qhov no los ntawm kev ua haujlwm yam tsis muaj kev qhia meej flex-basis
lossis border
. Muaj cov kev daws teeb meem rau cov laus browser versions, tab sis lawv yuav tsum tsis txhob tsim nyog yog tias koj lub hom phiaj browsers tsis poob rau hauv buggy versions.
Teem ib kab dav dav
Nws pib-layout rau flexbox daim phiaj kab kuj txhais tau hais tias koj tuaj yeem teeb tsa qhov dav ntawm ib kem thiab muaj cov nus muag kab tau hloov pauv nyob ib puag ncig nws. Koj tuaj yeem siv cov chav kawm ntawv teev tseg ua ntej (raws li qhia hauv qab no), daim phiaj sib xyaw, lossis qhov dav hauv kab. Nco ntsoov tias lwm cov kab yuav hloov loj txawm tias qhov dav ntawm kab nruab nrab.
Cov ntsiab lus dav sib txawv
Siv col-{breakpoint}-auto
cov chav kawm kom loj kab raws li qhov dav dav ntawm lawv cov ntsiab lus.
Cov chav kawm teb
Bootstrap daim phiaj suav nrog tsib qib ntawm cov chav kawm ua ntej rau kev tsim cov txheej txheem ua haujlwm. Customize qhov loj ntawm koj cov kab ntawv ntxiv me me, me, nruab nrab, loj, lossis cov khoom loj ntxiv txawm li cas los xij koj pom haum.
Tag nrho cov breakpoints
Rau daim phiaj uas zoo ib yam los ntawm qhov tsawg tshaj plaws ntawm cov khoom siv mus rau qhov loj tshaj plaws, siv cov .col
thiab .col-*
cov chav kawm. Qhia kom muaj tus lej lej thaum koj xav tau ib kab tshwj xeeb; txwv tsis pub, xav tias dawb los lo rau .col
.
Stacked rau kab rov tav
Siv ib txheej ntawm .col-sm-*
cov chav kawm, koj tuaj yeem tsim cov kab sib chaws yooj yim uas pib tawm hauv pawg thiab ua kab rov tav ntawm qhov chaw me me ( sm
).
Sib tov thiab sib tov
Tsis xav kom koj cov kab ke yooj yim nyob rau hauv ib co kab sib chaws? Siv cov chav kawm sib txawv rau txhua qib raws li xav tau. Saib cov piv txwv hauv qab no kom paub ntau ntxiv txog qhov nws ua haujlwm li cas.
Gutters
Gutters tuaj yeem hloov kho los ntawm kev sib cais tshwj xeeb padding thiab cov chav kawm tsis zoo ntawm cov khoom siv hluav taws xob. Txhawm rau hloov cov gutters nyob rau hauv ib kab, ua ke ib qho kev siv tsis zoo ntawm cov khoom siv hluav taws xob .row
thiab sib txuam padding utilities ntawm .col
s. Tus niam txiv .container
los yog .container-fluid
niam txiv kuj yuav tsum tau hloov kho ib yam nkaus kom tsis txhob muaj qhov tsis xav tau, siv dua cov khoom siv padding.
Nov yog ib qho piv txwv ntawm kev kho cov kab sib chaws Bootstrap ntawm qhov loj ( lg
) breakpoint thiab saum toj no. Peb tau nce lub .col
padding nrog .px-lg-5
, counteracted nrog .mx-lg-n5
rau ntawm niam txiv .row
thiab ces kho lub .container
wrapper nrog .px-lg-5
.
Kab kab
Siv cov .row-cols-*
chav kawm teb kom sai sai rau cov kab ntawv uas zoo tshaj plaws rau koj cov ntsiab lus thiab kev teeb tsa. Txawm li cas los xij, cov chav kawm ib txwm .col-*
siv rau cov kab ke ib leeg (xws li, .col-md-4
), cov chav kawm kab ke raug teeb tsa rau ntawm niam txiv .row
ua qhov luv.
Siv cov kab ke kab ke no kom sai sai tsim cov kab sib chaws yooj yim lossis tswj koj daim npav layouts.
Koj tuaj yeem siv Sass mixin nrog row-cols()
,:
Kev sib tw
Siv flexbox alignment utilities rau vertically thiab horizontally dlhos kab. Internet Explorer 10-11 tsis txhawb nqa ntsug ntawm cov khoom flex thaum lub thawv flex muaj min-height
raws li qhia hauv qab no. Saib Flexbugs #3 kom paub meej ntxiv.
Vertical alignment
Kab rov tav alignment
Tsis muaj gutters
Cov gutters ntawm txhua kab hauv peb cov chav kawm ntawv teev tseg ua ntej tuaj yeem raug tshem tawm nrog .no-gutters
. Qhov no tshem tawm qhov tsis zoo margin
ntawm .row
thiab kab rov tav padding
los ntawm txhua kab me nyuam tam sim ntawd.
Nov yog qhov chaws los tsim cov qauv no. Nco ntsoov tias kem overrides yog scoped rau tsuas yog thawj cov me nyuam kab thiab yog tsom los ntawm tus cwj pwm selector . Thaum qhov no tsim ib qho kev xaiv tshwj xeeb, kem padding tseem tuaj yeem hloov kho ntxiv nrog cov khoom siv sib nrug .
Xav tau ib tug ntug-rau-ntug tsim? Tso niam txiv .container
los .container-fluid
.
Hauv kev xyaum, ntawm no yog qhov nws zoo li. Nco ntsoov koj tuaj yeem txuas ntxiv siv qhov no nrog rau tag nrho lwm cov chav kawm ntawv teev tseg ua ntej (xws li kab dav dav, cov qib teb, rov txiav txim dua, thiab ntau dua).
Kem wrapping
Yog tias ntau tshaj 12 kab tau muab tso rau hauv ib kab, txhua pawg ntawm cov kab ntxiv yuav, raws li ib chav tsev, qhwv rau ib kab tshiab.
Txij li thaum 9 + 4 = 13 > 12, no 4-kem-div div tau qhwv mus rau ib kab tshiab ua ib chav sib txuas.
Cov kab tom ntej txuas ntxiv raws kab tshiab.
Kem so
Kev tawg kab mus rau kab tshiab hauv flexbox yuav tsum muaj lub hack me me: ntxiv cov khoom nrog width: 100%
txhua qhov chaw koj xav qhwv koj cov kab rau kab tshiab. Feem ntau qhov no ua tiav nrog ntau yam .row
s, tab sis tsis yog txhua txoj kev siv yuav suav rau qhov no.
Koj tseem tuaj yeem siv qhov kev so no ntawm cov ntsiab lus tshwj xeeb nrog peb cov khoom siv hluav taws xob ua haujlwm .
Reordering
Txiav cov chav kawm
Siv .order-
cov chav kawm los tswj qhov kev txiav txim pom ntawm koj cov ntsiab lus. Cov chav kawm no yog teb, yog li koj tuaj yeem teeb tsa order
los ntawm kev tawg (xws li, .order-1.order-md-2
). Xws li kev txhawb nqa rau 1
thoob 12
plaws txhua tsib kab sib chaws.
Kuj tseem muaj cov lus teb .order-first
thiab .order-last
cov chav kawm uas hloov cov order
ntsiab lus los ntawm kev thov order: -1
thiab order: 13
( order: $columns + 1
), feem. Cov chav kawm no tseem tuaj yeem sib xyaw nrog cov .order-*
chav kawm lej raws li xav tau.
Offsetting kab
Koj tuaj yeem offset kab kab hauv ob txoj hauv kev: peb .offset-
cov chav kawm kab sib txuas lus thiab peb cov khoom siv hluav taws xob . Cov chav kawm kab sib chaws yog qhov loj me kom phim cov kab thaum cov npoo muaj txiaj ntsig zoo dua rau cov txheej txheem nrawm uas qhov dav ntawm qhov offset sib txawv.
Cov chav kawm offset
Txav cov kab mus rau sab xis siv .offset-md-*
cov chav kawm. Cov chav kawm no nce sab laug ntawm ib kab los ntawm *
kab. Piv txwv li, .offset-md-4
txav .col-md-4
dhau plaub kab.
Ntxiv nrog rau kev tshem tawm kab ntawm cov ntsiab lus teb, koj yuav tsum tau rov pib dua offsets. Saib qhov no hauv kev nqis tes ua hauv daim phiaj piv txwv .
Cov khoom siv dav dav
Nrog rau kev txav mus rau flexbox hauv v4, koj tuaj yeem siv cov khoom siv paj nruag zoo .mr-auto
li yuam cov kwv tij sib nrug deb ntawm ib leeg.
Zes
Txhawm rau zes koj cov ntsiab lus nrog daim phiaj xwm txheej, ntxiv ib qho tshiab .row
thiab cov .col-sm-*
kab hauv kab uas twb muaj lawm .col-sm-*
. Nested kab yuav tsum muaj cov kab ke uas ntxiv txog 12 lossis tsawg dua (nws tsis tas yuav tsum tau siv tag nrho 12 kab muaj).
Sib tov
Thaum siv Bootstrap qhov chaw Sass cov ntaub ntawv, koj muaj kev xaiv siv Sass variables thiab mixins los tsim kev cai, semantic, thiab teb layouts nplooj ntawv. Peb cov chav kawm ntawv teev tseg ua ntej siv tib qhov sib txawv thiab cov mixins los muab cov chav kawm npaj txhij-rau-siv rau cov lus teb ceev ceev.
Hloov pauv
Qhov sib txawv thiab daim duab qhia kev txiav txim seb tus naj npawb ntawm kab, qhov dav ntawm lub qhov dej, thiab cov lus nug hauv xov xwm uas yuav pib cov kab ke. Peb siv cov no los tsim cov chav kawm ntawv teev tseg ua ntej sau tseg saum toj no, nrog rau cov kev cai mixins teev hauv qab no.
Mixins
Mixins tau siv ua ke nrog cov kab sib chaws sib txawv los tsim cov CSS semantic rau ib tus kab sib chaws.
Piv txwv kev siv
Koj tuaj yeem hloov kho qhov hloov pauv rau koj tus kheej cov txiaj ntsig kev cai, lossis tsuas yog siv cov mixins nrog lawv cov nqi qub. Ntawm no yog ib qho piv txwv ntawm kev siv lub neej ntawd teeb tsa los tsim ob kab layout nrog qhov sib txawv ntawm.
Customizing daim phiaj
Siv peb cov kab sib txuas ua ke Sass sib txawv thiab cov duab qhia chaw, nws muaj peev xwm ua kom haum rau cov chav kawm ntawv teev tseg ua ntej. Hloov tus naj npawb ntawm cov tiers, cov lus nug xov xwm qhov ntev, thiab lub thawv dav-ces rov ua dua.
Kum thiab gutters
Tus naj npawb ntawm kab sib chaws tuaj yeem hloov kho ntawm Sass variables. $grid-columns
yog siv los tsim qhov dav (hauv feem pua) ntawm txhua tus kab ke thaum $grid-gutter-width
teeb tsa qhov dav rau kab gutters.
Daim phiaj tiers
Tsiv dhau ntawm kab ntawv lawv tus kheej, koj tuaj yeem hloov kho tus lej ntawm kab sib chaws. Yog tias koj xav tau plaub kab sib chaws xwb, koj yuav hloov kho $grid-breakpoints
thiab $container-max-widths
rau qee yam zoo li no:
Thaum ua ib qho kev hloov pauv rau Sass variables lossis maps, koj yuav tsum tau txuag koj cov kev hloov pauv thiab rov ua dua. Ua li no yuav tso tawm cov txheej txheem tshiab ntawm cov chav kawm ntawv predefined rau kab dav dav, offsets, thiab kev txiav txim. Cov khoom siv pom kev pom tau zoo kuj yuav raug hloov kho kom siv cov kev cai breakpoints. Nco ntsoov teem daim phiaj qhov tseem ceeb hauv px
(tsis yog rem
, em
, lossis %
).