Bootstrap ka barokun
Bootstrap 4 bɛrɛbɛn ni an ka Sass fɛn caman sɛgɛsɛgɛli ye minnu bɛ don a kɔnɔ diɲɛ kɔnɔ cogoya fɛɛrɛw fɛ walasa ka barokun nɔgɔya ani ka fɛnw caman cili kɛ.
Bootstrap 3 kɔnɔ, barokunko tùn bɛ Laɲini kosɛbɛ ni fɛn caman sɛgɛsɛgɛli ye LESS kɔnɔ, CSS ladamulen na, ani barokun cogoya-sɛbɛn danfaralen dɔ min tùn bɛ an ka dist
dosiyew kɔnɔ. Ni cɛsiri dɔw kɛra, mɔgɔ bɛ se ka Bootstrap 3 cogoya labɛn kokura pewu k’a sɔrɔ a ma maga filenw kolomaw la. Bootstrap 4 bɛ fɛɛrɛ dɔ di min bɛ dɔn, nka a tɛ kelen ye dɔɔnin.
Sisan, barokun bɛ Kɛ ni Sass fɛn caman sɛgɛsɛgɛli ye, Sass kartiw, ani CSS ladamulen. Barokun cogoya sɛbɛn min ɲɛsinnen bɛ o ma tugun, o tɛ yen; o nɔ na, i bɛ se ka barokun min bɛ a kɔnɔ, o kɛ sababu ye ka fɛnw fara ɲɔgɔn kan minnu bɛ fɛnw jiginni, biɲɛw ani fɛn wɛrɛw fara a kan.
Baara kɛ ni an ka source Sass files ye walasa ka nafa sɔrɔ variables, maps, mixins ani fɛn wɛrɛw la.
Ni aw bɛ se tuma o tuma, aw kana Bootstrap ka filenw kolomaw sɛmɛntiya. Sass fɛ, o kɔrɔ ye k'i yɛrɛ ka stylesheet (fɔlikan) Dabɔ min bɛ Bootstrap (Bootstrap) Ladon walasa i ka Se k'a Lakodɔn k'a janya. Ni an y’a miiri ko i bɛ baara kɛ ni pake ɲɛmɔgɔ ye i n’a fɔ npm, i bɛna filen dɔ sɔrɔ min bɛ i n’a fɔ nin:
N’i y’an ka source files telesarse ani n’i tɛ baara kɛ ni package manager ye, i b’a fɛ ka fɛn dɔ sigi sen kan i bolo fɛ min ni o jɔcogo bɔlen don, ka Bootstrap ka source files to u dan na ni i yɛrɛ ta ye.
I ka custom.scss
, i bɛ Bootstrap ka source Sass filew ladon. Sugandili fila bɛ aw bolo: Bootstrap bɛɛ don a kɔnɔ, walima aw mago bɛ yɔrɔ minnu na, aw bɛ olu ta. An bɛ dusu don o labanw kɔnɔ, hali n’a y’a sɔrɔ aw k’a dɔn ko wajibi dɔw ni fɛn dɔw bɛ yen minnu bɛ tali kɛ an ka yɔrɔw bɛɛ la. Aw fana bɛna a ɲini ka JavaScript dɔw Dòn an ka 'pluginw na.
Ni o sigicogo in bɛ sen na, i bɛ se ka daminɛ ka Sass fɛn caman sɛmɛntiya ani ka kartiw dɔw ladilan i ka custom.scss
. Aw bɛ se fana ka Bootstrap yɔrɔ dɔw farali daminɛ // Optional
dakun jukɔrɔ i n’a fɔ aw mago bɛ cogo min na. An b’a Fɔ ko i ka baara Kɛ ni import stack dafalen ye ka Bɔ an ka bootstrap.scss
dosiye la k’a Kɛ i ka daminɛyɔrɔ ye.
Sass bεε bε Bootstrap 4 kɔnɔ, !default
darapo bε yen min b’a To i bε se ka bεnkansεbεn nafama bεε bε bεn i yɛrɛ ka Sass kɔnɔ k’a sɔrɔ i ma Bootstrap ka source code bε Yεlεma. Yɛlɛmafɛnw kopi kɛ ani k’u nɔrɔ i n’a fɔ a mago bɛ cogo min na, k’u nafaw sɛmɛntiya, ani ka !default
darapo bɔ. Ni fɛn dɔ bɛ Di a ma kaban, o tuma a tɛna Segin ka Di a ma ni nafaw ye minnu bɛ Bootstrap kɔnɔ.
Aw bɛ Bootstrap ka fɛn caman sɛgɛsɛgɛli dafalen sɔrɔ scss/_variables.scss
.
Variable overrides (daɲɛw sɛgɛsɛgɛli) minnu bɛ Sass file kelen kɔnɔ, olu bɛ se ka na ka kɔn variables defaults ɲɛ walima u kɔfɛ. Nka ni i bɛ Sass filenw bɛɛ lajɛlen sɛgɛsɛgɛli Kɛ, i ka sɛgɛsɛgɛliw ka kan ka Nà sani i ka Bootstrap ka Sass filenw Ladon.
Nin ye misali ye min bɛ fɛn caman Changer background-color
ani color
for the <body>
ni i bɛ Bootstrap don ani ka a lajɛ npm fɛ:
Aw bɛ segin a kan i n’a fɔ a mago bɛ fɛn o fɛn na Bootstrap kɔnɔ, diɲɛ sugandiliw fana sen bɛ o la minnu bɛ duguma.
Bootstrap 4 kɔnɔ, Sass karti damadɔ bɛ yen, nafa fila-fila minnu bɛ CSS ni ɲɔgɔn cɛ denbayaw labɔli nɔgɔya. An bɛ baara kɛ ni Sass kartiw ye an ka kulɛriw, grid breakpoints ani fɛn wɛrɛw kama. I n’a fɔ Sass bεε bε bεn cogo min na, Sass kartiw bεε la, !default
darapo bε yen wa u bε se ka bεn ani ka janya.
An ka Sass karti dɔw bɛ fara ɲɔgɔn kan ka kɛ lankolonw ye ka kɛɲɛ ni u ka daminɛ ye. O bɛ kɛ walasa ka sira di Sass karti dilen dɔ bonya nɔgɔya ma, nka a bɛ na ni musaka ye min bɛ kɛ sababu ye ka fɛnw bɔ karti dɔ kɔnɔ ka gɛlɛya dɔɔnin.
Walasa ka kulɛri dɔ sɛmɛntiya min bɛ an ka $theme-colors
karti kɔnɔ, i ka ninnu fara i ka Sass file ladamulen kan:
Walasa ka kulɛri kura $theme-colors
fara , i ka kilisi kura ni nafa fara a kan:
Walasa ka kulɛriw bɔ $theme-colors
, walima karti wɛrɛ la, baara kɛ ni map-remove
. Aw k’a dɔn ko aw ka kan k’a don an ka ɲininiw ni sugandiliw cɛ:
Bootstrap bɛ a miiri ko kilisi kɛrɛnkɛrɛnnen dɔw bɛ Sass kartiw kɔnɔ i n’a fɔ an yɛrɛ bɛ baara kɛ cogo min na ani k’u janya. Ni i bɛ karti minnu bɛ a kɔnɔ, i bɛ olu kɛ ka kɛɲɛ ni i yɛrɛ sago ye, i bɛ se ka filiw sɔrɔ yɔrɔ min na Sass karti kɛrɛnkɛrɛnnen dɔ ka kilisi bɛ baara kɛ.
Misali la, an bɛ baara Kɛ ni primary
, success
, ani danger
butɔnw ye minnu bɛ Bɔ ka $theme-colors
ɲɛsin jɛgɛnsira, butɔni ani foroko cogoyaw ma. Nin kilisi ninnu nafaw falen-falen man kan ka ko si jira, nka n’i y’u bɔ, o bɛ se ka kɛ sababu ye ka Sass ka jatebɔko gɛlɛyaw lase. O ko ninnu na, i b’a fɛ ka Sass kode caman sɛmɛntiya min bɛ baara kɛ ni o nafaw ye.
Bootstrap bɛ baara Kɛ ni Sass baarakɛcogo damadɔ ye, nka kulu fitinin dɔrɔn de bɛ Kɛ ka ɲɛsin barokun caman ma. An ye baarakɛcogo saba Dòn a la walasa ka nafaw Sɔrɔ ka Bɔ kulɛri kartiw la:
Olu b’a To i bɛ Se ka kulɛri kelen Tà Sass karti la i n’a fɔ i bɛ baara Kɛ ni kulɛri caman ɲɔgɔnna ye cogo min na ka Bɔ v3 la.
An fana bɛ baara wɛrɛ Kɛ walasa ka kulɛri hakɛ$theme-colors
kɛrɛnkɛrɛnnen dɔ Sɔrɔ karti kan. Nivo negative nafaw bɛna kulɛri yeelen, ka sɔrɔ nivo sanfɛtaw bɛna dibi don.
Tiɲɛ na, i tun bɛ baara Weele ka tɛmɛ paramɛtɛrɛ fla la: kulɛri tɔgɔ ka Bɔ $theme-colors
(misali la, fɔlɔ walima farati) ani jatebla hakɛ dɔ.
Baarakɛcogo wɛrɛw bɛ Se ka Fàra ɲɔgɔn kan don nataw la walima i yɛrɛ ka Sass ladamulen walasa ka nivo baarakɛcogo Dabɔ Sass karti wɛrɛw kama, walima hali jenɛriki dɔ n’i b’a fɛ ka kumakan fɔ ka caya.
An bɛ baara wɛrɛ min Kɛ Bootstrap kɔnɔ o ye kulɛri danfara baarakɛcogo ye, color-yiq
. A bɛ baara Kɛ ni YIQ kulɛri yɔrɔ ye walasa ka yeelen ( #fff
) walima dibi ( #111
) danfaralan dɔ Lasegin a yɛrɛma ka Da basigi kulɛri kofɔlen kan. Nin baara in nafa ka bon kɛrɛnkɛrɛnnenya la mixins walima loops (lupulu) la i bɛ kalasi caman lawuli yɔrɔ minnu na.
Misali la, walasa ka kulɛriw sɛgɛsɛgɛli kɛ ka bɔ an ka $theme-colors
karti la:
A bɛ se ka kɛ fana danfara magow la minnu bɛ kɛ siɲɛ kelen:
Aw bɛ se fana ka basigi kulɛri dɔ jira ni an ka kulɛri karti baarakɛcogo ye:
Bootstrap 4 bɛrɛbɛn ni an ka custom variables file ye min bɛ a kɔnɔ ani ka diɲɛ CSS fɛɛrɛw wuli nɔgɔya la ni $enable-*
Sass variables kura ye. Override a variable's value ani ka recompile ni npm run test
i n'a fɔ a mago bɛ cogo min na.
Aw bɛ se ka nin fɛn caman ɲɔgɔnna sɔrɔ ani k’u labɛn diɲɛ sugandili jɔnjɔnw kama Bootstrap ka scss/_variables.scss
dosiye kɔnɔ.
Yɛlɛma-yɛlɛma | Nafaw | Cogojirali |
---|---|---|
$spacer |
1rem (default), walima nafa o nafa > 0 |
a bɛ spacer nafa dafalen jira walasa ka an ka spacer nafalanw lawuli porogaramu fɛ . |
$enable-rounded |
true (default) walimafalse |
A bɛ se ka kɛcogo ɲɛfɔlenw border-radius kɛ yɔrɔ suguya caman kan. |
$enable-shadows |
true walima false (default) . |
A bɛ se ka kɛcogo ɲɛfɔlenw box-shadow kɛ yɔrɔ suguya caman kan. |
$enable-gradients |
true walima false (default) . |
A bɛ se ka gradients (gradients) minnu ɲɛfɔlen don ka kɔn, background-image styles (fɔcogo) fɛ component (yɔrɔ) suguya caman kan. |
$enable-transitions |
true (default) walimafalse |
transition A bɛ se ka s ɲɛfɔlenw kɛ yɔrɔ suguya caman kan. |
$enable-hover-media-query |
true walima false (default) . |
A ma deli ka kɛ |
$enable-grid-classes |
true (default) walimafalse |
A bɛ CSS kalanw bɔli daminɛ grid sitɛmu kama (misali la, .container , .row , .col-md-1 , wdfl). |
$enable-caret |
true (default) walimafalse |
A bɛ se ka kɛ sababu ye ka pseudo element caret kɛ .dropdown-toggle . |
$enable-print-styles |
true (default) walimafalse |
A bɛ se ka cogoyaw kɛ walasa ka sɛbɛnni kɛcogo ɲɛ. |
Bootstrap ka fɛn suguya caman ni nafalan caman bɛ jɔ ni kulɛriw ye minnu ɲɛfɔlen don Sass karti dɔ kɔnɔ. Nin karti in bɛ se ka loopu kɛ Sass kɔnɔ walasa ka sariyaw sigi senkan teliya la.
Kulɛriw bɛɛ bɛ sɔrɔ Bootstrap 4 kɔnɔ, olu bɛ sɔrɔ i n’a fɔ Sass variables ani Sass map in scss/_variables.scss
file. O bɛna bonya bɔko misɛnnin nataw la walasa ka biɲɛ wɛrɛw fara a kan, i n’a fɔ an bɛ palɛti gris min don a la kaban.
Aw bɛ se ka baara kɛ ni ninnu ye cogo min na aw ka Sass kɔnɔ, o filɛ nin ye:
Kulɛri nafama kalanw fana bɛ sɔrɔ sigicogo color
ni background-color
.
Don nataw la, an bɛna a laɲini ka Sass kartiw ni fɛn caman ɲɔgɔnna di kulɛri kelen-kelen bɛɛ ɲɛw ma i n’a fɔ an y’a kɛ cogo min na ni kulɛriw ye minnu bɛ duguma.
An bɛ baara Kɛ ni kulɛri bɛɛ kulu fitinin dɔ ye walasa ka kulɛri fitinin dɔ Dabɔ walasa ka kulɛriw labɛn, o fana bɛ Sɔrɔ i n’a fɔ Sass fɛn caman sɛgɛsɛgɛli ani Sass karti Bootstraps ka scss/_variables.scss
dosiye kɔnɔ.
A ye fɛn caman sɛgɛsɛgɛli kɛ fɛn caman sɛgɛsɛgɛli la ani Sass karti in scss/_variables.scss
for consistent shades of gray across your project.
, kɔnɔ scss/_variables.scss
, i bɛ Bootstrap ka kulɛri caman ɲɔgɔnna sɔrɔ ani Sass karti. $colors
Sass karti misali dɔ filɛ nin ye :
Nafaw fara ɲɔgɔn kan, ka bɔ yen, walima ka fɛn dɔw sɛmɛntiya karti kɔnɔ walasa ka u baaracogo kura ye yɔrɔ caman wɛrɛw la. A fɔ man di nka nin waati in na, yɔrɔ bɛɛ tɛ baara kɛ ni Sass karti in ye. Kuma kura nataw bɛna an jija ka ɲɛtaa kɛ o ko la. Fɔ ka se o waati ma, aw bɛ labɛn kɛ ka baara kɛ ni ${color}
fɛn caman sɛgɛsɛgɛli ye ani nin Sass karti in.
Bootstrap ka fɛn caman ni a ka nafalanw bɛ jɔ ni @each
lupuw ye minnu bɛ segin-ka-bɔ Sass karti kan. O bɛ dɛmɛ kɛrɛnkɛrɛnnenya la ka ɲɛsin fɛn dɔ ka fɛn caman ɲɔgɔnnabɔli ma an fɛ $theme-colors
ani ka fɛn caman ɲɔgɔnna jaabiw dilan kariyɔrɔ kelen-kelen bɛɛ la. Ni i bɛ nin Sass kartiw ladilan ani ka u labɛn kokura, i bɛna i yɛrɛ ye i ka fɛn caman Changements (Yɛlɛma) bɛ jira nin loops (lupulu) ninnu na.
Bootstrap ka yɔrɔ caman bɛ jɔ ni base-modifier class approach ye. O kɔrɔ ye ko cogoya fanba bɛ sɔrɔ basigi kalasi dɔ la (misali la, .btn
) k’a sɔrɔ cogoya caman ɲɔgɔnna bɛ dan fɛn caman sɛmɛntiyalanw ma (misali la, .btn-danger
). O bεε lajɛlen bε jɔ ka Bɔ $theme-colors
karti la walasa ka an ka bεnkansεbεn kalasi hakɛ n’a tɔgɔ bεε Labɛn.
$theme-colors
An bɛ loop kɛ cogo min na karti kan walasa ka modifiers (daɲɛw) lawuli .alert
component (yɔrɔ) la ani an ka .bg-*
background utilities (fɔlifɛnw) bɛɛ la, misali fila filɛ nin ye .
Nin Sass loop ninnu tɛ dan kulɛri kartiw dɔrɔn ma, olu fana. Aw bɛ se fana ka jaabi caman ɲɔgɔnna caman lawuli aw ka yɔrɔw walima aw ka nafamafɛnw na. An ka misali ta an ka jaabi sɛbɛnni ɲɔgɔndan nafamayɔrɔw la an bɛ min na an bɛ @each
lupu dɔ ɲagami $grid-breakpoints
Sass karti kama ni media ɲininkali dɔ ye min kɔnɔ.
Ni i ka kan ka i ka , fɛn caman sɛmɛntiya $grid-breakpoints
, i ka fɛn caman Changements bɛna kɛ ka ɲɛsin loop bɛɛ ma minnu bɛ segin-ka-bɔ o karti kan.
Bootstrap 4 bɛ CSS ladamucogo (variables) tan ni fila ɲɔgɔn Dòn a ka CSS lajɛlen kɔnɔ. Olu bɛ nafaw sɔrɔ nɔgɔya la minnu bɛ kɛ ka caya i n’a fɔ an ka barokun kulɛriw, kariyɔrɔw, ani sɛbɛnnibolo fɔlɔw kuluw ni i bɛ baara kɛ i ka navigatɔrɔ ka Inspecteur kɔnɔ, kode sandbox kɔnɔ, walima prototyping caman na.
An bɛ fɛn minnu Blà ɲɔgɔn na, olu filɛ nin ye (a kɔlɔsi ko the :root
is required). U bɛ sɔrɔ an ka _root.scss
dosiye kɔnɔ.
CSS bεε bε Se ka bεnkansεbεn di ni Sass ka bεnkanw ye, nka k’a sɔrɔ u mago tε ɲɔgɔndan na sani u ka Di navigatɔrɔ ma. Misali la, yan an bɛ an ka ɲɛ in sɛbɛnnibolow ni jɛgɛncogo cogoyaw Lasegin ni CSS fɛn caman sɛgɛsɛgɛli ye.
Hali n’an ye kariyɔrɔw Dòn an ka CSS fɛn caman sɛgɛsɛgɛli la fɔlɔ (misali la, --breakpoint-md
), ninnu tɛ Dɛmɛ kunnafonidilanw ɲininkaliw la , nka u bɛ Se ka baara Kɛ hali bi sariyaw kɔnɔ kunnafonidilanw ɲininkaliw la. O bεnkansεbεnw bε To CSS lajɛlen kɔnɔ walasa ka kɔ̀rɔbalen Kɛ k’a da a kan u bɛ Se ka baara Kɛ ni JavaScript ye. Aw ye kunnafoni wɛrɛw sɔrɔ spec kɔnɔ.
Fɛn minnu tɛ dɛmɛ sɔrɔ , olu misali dɔ filɛ nin ye :
Wa, min bɛ dɛmɛ sɔrɔ, o misali dɔ filɛ nin ye: