Tanya ƒe Bootstrap
Trɔ asi le Bootstrap 4 ŋu kple míaƒe Sass tɔtrɔ yeye siwo wotu ɖe eme na xexeame katã ƒe atsyã ƒe tiatia hena tanya bɔbɔe kple akpa ƒe tɔtrɔ.
Le Bootstrap 3 me la, tanyawo ƒe akpa gãtɔ tso tɔtrɔwo ƒe tsɔtsɔ ɖe le LESS me, CSS si wowɔ ɖe ɖoɖo nu, kple tanya ƒe atsyã gbalẽvi si to vovo si míetsɔ de míaƒe dist
faɛlwo me gbɔ. Ne ame aɖe dze agbagba vie la, ate ŋu atrɔ asi le Bootstrap 3 ƒe dzedzeme ŋu keŋkeŋ evɔ meka asi faɛl veviawo ŋu o. Bootstrap 4 naa mɔnu nyanyɛ aɖe, gake wòto vovo vie.
Fifia, wowɔa tanya to Sass ƒe tɔtrɔwo, Sass ƒe anyigbatatawo, kple CSS si wowɔ ɖe ɖoɖo nu dzi. Tanya ƒe atsyãgbalẽ si woɖo ɖi na ame aɖeke megali o; ke boŋ àte ŋu ana tanya si wotu ɖe eme la nate ŋu atsɔ gradients, shadows, kple bubuwo akpe ɖe eŋu.
Zã míaƒe dzɔtsoƒe Sass faɛlwo nàtsɔ awɔ tɔtrɔwo, anyigbatatawo, mixins, kple bubuwo ŋudɔ.
Ɣesiaɣi si wòanya wɔ la, ƒo asa na asitɔtrɔ le Bootstrap ƒe faɛl veviwo ŋu. Le Sass gome la, ema fia be nàwɔ wò ŋutɔ wò atsyãgbalẽ si xɔa Bootstrap ale be nàte ŋu atrɔ asi le eŋu ahakekee ɖe enu. Ne míetsɔe be èle package manager abe npm ene zãm la, àkpɔ faɛl ƒe ɖoɖo si le abe esia ene:
Ne èɖe míaƒe dzɔtsoƒe faɛlwo eye mèle package manager zãm o la, àdi be yeatsɔ asi aɖo nane si sɔ kple ɖoɖo ma, si ana Bootstrap ƒe dzɔtsoƒe faɛlwo nato vovo tso tɔwò gbɔ.
Le wò custom.scss
, àxɔ Bootstrap ƒe dzɔtsoƒe Sass faɛlwo. Tiatia eve le asiwò: tsɔ Bootstrap la katã de eme, alo nàtia akpa siwo nèhiã. Míele dzi dem ƒo na mamlɛtɔa, togbɔ be nyae be nudidi aɖewo kple nusiwo dzi woanɔ te ɖo le míaƒe akpawo katã me hã. Ahiã hã be nàde JavaScript aɖewo eme na míaƒe plugins.
Ne ɖoɖo ma le teƒea la, àte ŋu adze asitɔtrɔ le Sass ƒe tɔtrɔwo kple anyigbatata siwo le wò custom.scss
. Àteŋu adze Bootstrap ƒe akpa aɖewo tsɔtsɔ kpee hã gɔme le // Optional
akpaa te ne ehiã. Míeɖo aɖaŋu be nàzã import stack bliboa tso míaƒe bootstrap.scss
faɛl me abe wò gɔmedzedze ene.
Sass ƒe tɔtrɔ ɖesiaɖe le Bootstrap 4 me la de !default
aflaga si ɖe mɔ na wò be nàɖe asi le tɔtrɔ ƒe asixɔxɔ gbãtɔ ŋu le wò ŋutɔ wò Sass me evɔ màtrɔ asi le Bootstrap ƒe dzɔtsoƒe ƒe nuŋɔŋlɔ ŋu o. Kpɔ tɔtrɔwo ƒe kɔpi eye nàde wo eme alesi wòhiã, trɔ asi le woƒe asixɔxɔwo ŋu, eye nàɖe !default
aflagaa ɖa. Ne wotsɔ tɔtrɔ aɖe de asi na ame xoxo la, ekema womagagbugbɔe ade asi na to asixɔxɔ gbãtɔ siwo le Bootstrap me dzi o.
Àkpɔ Bootstrap ƒe tɔtrɔwo ƒe xexlẽdzesi bliboa le scss/_variables.scss
.
Tɔtrɔwo ƒe ʋuʋu le Sass faɛl ɖeka me ateŋu ava do ŋgɔ na tɔtrɔ gbãtɔwo alo le wo megbe. Ke hã, ne èle asi trɔm le Sass faɛlwo katã ŋu la, ele be wò asiɖeɖe le wo ŋu nava hafi nàxɔ Bootstrap ƒe Sass faɛlwo.
Kpɔɖeŋu aɖe si trɔa background-color
kple color
na <body>
ne wole Bootstrap xɔm hele eƒom ƒu to npm dzi lae nye esi:
Gbugbɔ gblɔ alesi wòhiã na tɔtrɔ ɖesiaɖe le Bootstrap me, si me xexeame katã ƒe tiatia siwo le ete hã le.
Bootstrap 4 la lɔ Sass anyigbatata ʋee aɖewo ɖe eme, asixɔxɔ vevi eve siwo nana wònɔa bɔbɔe be woawɔ CSS siwo do ƒome kplii ƒe ƒomewo. Míezãa Sass ƒe anyigbatatawo na míaƒe amadedewo, grid breakpoints, kple bubuwo. Abe Sass ƒe tɔtrɔwo ene la, Sass ƒe anyigbatatawo katã me !default
aflaga la le eye woateŋu axe mɔ ɖe wo nu ahakeke wo ɖe enu.
Woƒoa míaƒe Sass anyigbatata aɖewo nu ƒu ɖe ƒuƒluwo me le gɔmedzedzea me. Wowɔa esia be woaɖe mɔ be woakeke Sass ƒe anyigbatata aɖe ɖe enu bɔbɔe, gake eva le ga si woatsɔ ana nuwo ɖeɖe le anyigbatata dzi nasesẽ vie ta.
Ne èdi be yeatrɔ asi le amadede aɖe si li xoxo le míaƒe $theme-colors
anyigbatata dzi ŋu la, tsɔ nusiwo gbɔna kpe ɖe wò Sass faɛl si nèwɔ ɖe ɖoɖo nu ŋu:
Ne èdi be yeatsɔ amadede yeye akpe ɖe , ŋu $theme-colors
la, tsɔ safui yeyea kple asixɔxɔ kpee:
Ne èdi be yeaɖe amadedewo ɖa le $theme-colors
, alo anyigbatata bubu ɖesiaɖe dzi la, zã map-remove
. Nyae be ele be nàtsɔe ade míaƒe nudidiwo kple tiatiawɔblɔɖewo dome:
Bootstrap tsɔe be safui tɔxɛ aɖewo le Sass ƒe anyigbatatawo me abe alesi míezãe eye mía ŋutɔwo míekeke esiawo ɖe enu ene. Ne èle anyigbatata siwo le eme la trɔm la, àte ŋu ado go vodadawo le afisi wole Sass ƒe anyigbatata aɖe koŋ ƒe safui zãm le.
Le kpɔɖeŋu me, míezãa primary
, success
, kple danger
safui siwo tso $theme-colors
hena kadodowo, abɔtawo, kple nuŋlɔɖi ƒe nɔnɔmewo. Mele be safui siawo ƒe asixɔxɔwo ɖɔliɖɔli nahe nya aɖeke vɛ o, gake wo ɖeɖeɖa ateŋu ahe Sass ƒe nuƒoƒoƒu ƒe kuxiwo vɛ. Le nɔnɔme siawo me la, ahiã be nàtrɔ asi le Sass ƒe kɔda si wɔa asixɔxɔ mawo ŋudɔ la ŋu.
Bootstrap zãa Sass dɔwɔwɔ geɖewo, gake ƒuƒoƒo sue aɖe koe woateŋu awɔ dɔ le tanya gbadzaa me. Míetsɔ dɔwɔwɔ etɔ̃ de eme hena asixɔxɔwo xɔxɔ tso amadede ƒe anyigbatatawo me:
Esiawo na be nàte ŋu atia amadede ɖeka tso Sass ƒe anyigbatata me abe alesi nàzã amadede ƒe tɔtrɔ tso v3 me ene.
Dɔ bubu aɖe hã le mía si hena amadede ƒe seƒe$theme-colors
aɖe koŋ xɔxɔ tso anyigbatataa dzi. Negative level values ana amadedea nakɔ, gake level siwo kɔkɔ wu ado viviti.
Le nuwɔna me la, àyɔ dɔwɔwɔa eye nàto parameter eve me: amadede ƒe ŋkɔ tso $theme-colors
(le kpɔɖeŋu me, gbãtɔ alo afɔku) kple xexlẽdzesi ƒe dzidzenu.
Woateŋu atsɔ dɔwɔwɔ bubuwo akpe ɖe eŋu le etsɔme alo wò ŋutɔ wò Sass si wowɔ ɖe ɖoɖo nu be nàwɔ level dɔwɔwɔwo na Sass ƒe anyigbatata bubuwo, alo gɔ̃ hã generic ɖeka ne èdi be yeanye nyagbɔgblɔ geɖe wu.
Dɔ bubu ɖeka si míetsɔ de Bootstrap mee nye amadede ƒe vovototodedeameme ƒe dɔwɔwɔ, color-yiq
. Ezãa YIQ ƒe amadede ƒe teƒea tsɔ trɔa amadede si me kɔ ( #fff
) alo viviti ( #111
) si to vovo le eɖokui si si wotu ɖe gɔmeɖoanyi ƒe amadede si woɖo dzi. Dɔwɔwɔ sia ɖea vi ŋutɔ na mixins alo loops afisi nèle klass geɖewo wɔm le.
Le kpɔɖeŋu me, be nàwɔ amadede ƒe nɔnɔmetatawo tso míaƒe $theme-colors
anyigbatata dzi la:
Woate ŋu azãe hã na vovototodedeameme ƒe hiahiã siwo hiã zi ɖeka:
Àte ŋu agblɔ gɔmeɖoanyi ƒe amadede hã kple míaƒe amadede ƒe nɔnɔmetata ƒe dɔwɔwɔwo:
Trɔ asi le Bootstrap 4 ŋu kple míaƒe tɔtrɔ tɔxɛwo ƒe faɛl si wotu ɖe eme eye nàtrɔ xexeame katã ƒe CSS ƒe didiwo bɔbɔe kple $enable-*
Sass tɔtrɔ yeyewo. Trɔ asi le tɔtrɔ aɖe ƒe asixɔxɔ ŋu eye nàgbugbɔ aƒo ƒu kple npm run test
alesi wòhiã.
Àteŋu akpɔ tɔtrɔ siawo eye nàtrɔ asi le wo ŋu na xexeame katã ƒe tiatia veviwo le Bootstrap ƒe scss/_variables.scss
faɛl me.
Nusiwo trɔna | Dzidzenuwo | Nuɖᴐɖᴐ |
---|---|---|
$spacer |
1rem (si woɖo ɖi), alo asixɔxɔ ɖesiaɖe > 0 |
Tsɔ spacer ƒe asixɔxɔ gbãtɔ si woatsɔ awɔ míaƒe spacer dɔwɔnuwo le ɖoɖowɔɖi me . |
$enable-rounded |
true (si woɖo ɖi) alofalse |
Enaa border-radius atsyã siwo woɖo ɖi do ŋgɔ la wɔa dɔ le akpa vovovowo dzi. |
$enable-shadows |
true alo false (si woɖo ɖi) . |
Enaa box-shadow atsyã siwo woɖo ɖi do ŋgɔ la wɔa dɔ le akpa vovovowo dzi. |
$enable-gradients |
true alo false (si woɖo ɖi) . |
Enaa gradients siwo woɖo do ŋgɔ la wɔa dɔ to background-image atsyãwo dzi le akpa vovovowo dzi. |
$enable-transitions |
true (si woɖo ɖi) alofalse |
Enaa transition s siwo woɖo ɖi do ŋgɔ la wɔa dɔ le akpa vovovowo dzi. |
$enable-hover-media-query |
true alo false (si woɖo ɖi) . |
Woɖe asi le eŋu |
$enable-grid-classes |
true (si woɖo ɖi) alofalse |
Enaa CSS ƒe klasswo ƒe dzidzi na grid ɖoɖoa (le kpɔɖeŋu me, .container , .row , .col-md-1 , kple bubuawo). |
$enable-caret |
true (si woɖo ɖi) alofalse |
Enaa pseudo element caret wɔa dɔ le .dropdown-toggle . |
$enable-print-styles |
true (si woɖo ɖi) alofalse |
Enaa atsyãwo wɔa dɔ hena agbalẽtata nyuie wu. |
Wotu Bootstrap ƒe akpa vovovoawo kple dɔwɔnu geɖewo to amadede siwo kplɔ wo nɔewo ɖo siwo woɖe fia le Sass ƒe anyigbatata me dzi. Woateŋu atsɔ anyigbatata sia awɔ loop le Sass me be woawɔ se siwo kplɔ wo nɔewo ɖo kaba.
Amadede siwo katã le Bootstrap 4 me, li abe Sass ƒe tɔtrɔwo kple Sass ƒe nɔnɔmetata le scss/_variables.scss
faɛl me ene. Woakeke esia ɖe enu le nu suesuesue siwo woaɖe ɖe go emegbe me be woatsɔ amadede bubuwo akpe ɖe eŋu, abe greyscale palette si míetsɔ de eme xoxo ene.
Ale si nàte ŋu azã esiawo le wò Sass me enye si:
Amadede ƒe dɔwɔnu ƒe klasswo hã li na ɖoɖowɔwɔ color
kple background-color
.
Le etsɔme la, míaɖoe be míana Sass ƒe anyigbatatawo kple tɔtrɔwo na amadede ɖesiaɖe ƒe vɔvɔliwo abe alesi míewɔe kple amadede ɣi siwo le ete ene.
Míezãa amadedewo katã ƒe akpa sue aɖe tsɔ wɔa amadede ƒe ƒuƒoƒo sue aɖe hena amadede ƒe ɖoɖowo wɔwɔ, si hã li abe Sass ƒe tɔtrɔwo kple Sass ƒe anyigbatata le Bootstraps ƒe scss/_variables.scss
faɛl me.
Gbeɖiɖi ƒe tɔtrɔwo ƒe ƒuƒoƒo si keke ta kple Sass ƒe nɔnɔmetata le scss/_variables.scss
hena amadede ɣi ƒe vɔvɔli siwo mewɔa tɔtrɔ o le wò dɔa katã me.
Le scss/_variables.scss
, me la, àkpɔ Bootstrap ƒe amadede ƒe tɔtrɔwo kple Sass ƒe anyigbatata. $colors
Sass ƒe anyigbatata ƒe kpɔɖeŋu aɖee nye esi :
Tsɔ asixɔxɔwo kpee, ɖe wo ɖa, alo trɔ asi le wo ŋu le anyigbatataa me be nàtrɔ asi le alesi wozãa wo le akpa bubu geɖe me ŋu. Nublanuitɔe le ɣeyiɣi sia me la, menye akpa ɖesiaɖee zãa Sass ƒe anyigbatata sia o. Nu yeye siwo woawɔ le etsɔme adze agbagba be yewoawɔ esia wòanyo ɖe edzi. Vaseɖe ɣemaɣi la, wɔ ɖoɖo ɖe ${color}
tɔtrɔawo kple Sass ƒe anyigbatata sia zazã ŋu.
Wotu Bootstrap ƒe akpa kple dɔwɔnu geɖewo kple @each
loop siwo gbugbɔna yia Sass ƒe anyigbatata dzi. Esia kpena ɖe ame ŋu vevietɔ na akpa aɖe ƒe tɔtrɔwo wɔwɔ to míaƒe $theme-colors
kple tɔtrɔ siwo ɖoa nya ŋu wɔwɔ na breakpoint ɖesiaɖe. Ne èle Sass ƒe anyigbatata siawo trɔm eye nègbugbɔ ƒo wo nu ƒu la, àkpɔ wò tɔtrɔwo le ɖokuiwò si wòadze le loop siawo me.
Wotu Bootstrap ƒe akpa geɖewo kple base-modifier class mɔnu. Esia fia be atsyã ƒe akpa gãtɔ le gɔmeɖoanyi ƒe hatsotso aɖe me (le kpɔɖeŋu me, .btn
) esime atsyã ƒe tɔtrɔwo le tɔtrɔ ƒe hatsotsowo me ko (le kpɔɖeŋu me, .btn-danger
). Wotu tɔtrɔɖenu ƒe hatsotso siawo tso $theme-colors
anyigbatata dzi be woawɔ tɔtrɔ ɖe míaƒe tɔtrɔ ƒe hatsotsowo ƒe xexlẽme kple ŋkɔ ŋu.
Alesi míewɔa loop ɖe $theme-colors
anyigbatata dzi tsɔ wɔa tɔtrɔwo ɖe .alert
akpaa kple míaƒe .bg-*
megbe dɔwɔnuwo katã ŋu ƒe kpɔɖeŋu evee nye esi.
Sass loop siawo menye amadede ƒe anyigbatatawo ɖeɖeko o, nenema ke. Àte ŋu awɔ wò akpawo alo dɔwɔnuwo ƒe tɔtrɔ siwo ɖoa nya ŋu hã. Tsɔ kpɔɖeŋu míaƒe ŋuɖoɖo nuŋɔŋlɔ ƒe ɖoɖowɔwɔ dɔwɔnuwo afisi míetsakaa @each
loop na $grid-breakpoints
Sass anyigbatata kple media biabia de eme.
Ne ehiã be nàtrɔ asi le wò $grid-breakpoints
, wò tɔtrɔwo awɔ dɔ ɖe loop siwo katã gbugbɔna le anyigbatata ma dzi la dzi.
Bootstrap 4 tsɔ CSS ƒe nɔnɔme tɔxɛwo (trɔtrɔwo) siwo ade blaeve vɔ eve de eƒe CSS si woƒo ƒu me. Esiawo naa mɔnukpɔkpɔ bɔbɔe be nàkpɔ asixɔxɔ siwo wozãna zi geɖe abe míaƒe tanya ƒe amadedewo, breakpoints, kple ŋɔŋlɔdzesi gbãtɔwo ƒe ƒuƒoƒo ne èle dɔ wɔm le wò web-browser ƒe Inspector, code sandbox, alo general prototyping me.
Trɔtrɔ siwo míetsɔ de eme lae nye esi (de dzesii be the :root
is required). Wole míaƒe _root.scss
faɛl la me.
CSS ƒe tɔtrɔwo naa asitɔtrɔ le nɔnɔmewo ŋu abe Sass ƒe tɔtrɔwo ene, gake mehiã be woaƒo wo nu ƒu hafi atsɔ wo ana web-browser la o. Le kpɔɖeŋu me, afisia míele míaƒe axaa ƒe nuŋɔŋlɔ kple kadodo ƒe atsyãwo gbugbɔ ɖom kple CSS tɔtrɔwo.
Togbɔ be míetsɔ breakpoints de míaƒe CSS tɔtrɔwo me gbã (le kpɔɖeŋu me, --breakpoint-md
), womedoa alɔ esiawo le media biabiawo me o , gake woateŋu azã wo kokoko le sewo me le media biabiawo me. Brekpoint ƒe tɔtrɔ siawo gakpɔtɔ le CSS si woƒo ƒu me hena megbedede ƒe sɔsɔ ne wobu be woateŋu azã wo to JavaScript dzi. Srɔ̃ nu geɖe le spec la me.
Nusiwo womeda asi ɖe edzi o ƒe kpɔɖeŋu aɖee nye esi:
Eye nusiwo ŋu wodoa alɔe ƒe kpɔɖeŋu aɖee nye esi: