Theming Bootstrap
Yenza ngokwezifiso i-Bootstrap yesi-4 ngezinto zethu ezintsha ezakhelwe ngaphakathi ze-Sass zokhetho lwesitayile sehlabathi ukulungiselela umxholo olula kunye notshintsho lwamacandelo.
Intshayelelo
Kwi-Bootstrap 3, i-theming yayiqhutywa ubukhulu becala kukudlula okuguquguqukayo kwi-LESS, i-CSS yesiko, kunye necwecwe lesitayile somxholo owahlukileyo esiwufake dist
kwiifayile zethu. Ngomzamo othile, umntu unokuphinda ahlengahlengise ngokupheleleyo inkangeleko yeBootstrap 3 ngaphandle kokuchukumisa iifayile ezingundoqo. I-Bootstrap 4 ibonelela ngendlela eqhelekileyo, kodwa eyahlukileyo kancinane.
Ngoku, umxholo ufezekiswa ngoguquguquko lweSass, iimephu zeSass, kunye neCSS yesiko. Akusekho cwecwe lesimbo lomxholo ozinikeleyo; endaweni yoko, unokwenza umxholo owakhelwe-ngaphakathi ukongeza i-gradients, izithunzi, kunye nokunye.
Sass
Sebenzisa umthombo wethu weefayile zeSass ukuthatha ithuba lokuguquguquka, iimephu, imixube, kunye nokunye. Kulwakhiwo lwethu sonyuse iSass ukuchaneka kokujikeleza ukuya ku-6 (ngokungagqibekanga sisi-5) ukunqanda imiba ngokurhangqwa kwesikhangeli.
Ubume befayile
Nanini na kunokwenzeka, kunqanda ukulungisa iifayile ezingundoqo zeBootstrap. KwiSass, oko kuthetha ukwenza elakho iphepha lesimbo elingenisa ngaphandle iBootstrap ukuze ukwazi ukuyiguqula kwaye uyandise. Ucinga ukuba usebenzisa umphathi wephakheji njenge-npm, uya kuba nesakhiwo sefayile esijongeka ngolu hlobo:
Ukuba ukhuphele iifayile zethu zemvelaphi kwaye awusebenzisi umphathi wepakethe, uya kufuna ukuseta ngesandla into efana neso sakhiwo, ugcine iifayile zemvelaphi yeBootstrap zahlukile kweyakho.
Ukungenisa elizweni
Kweyakho custom.scss
, uya kungenisa iifayile zeSass zomthombo weBootstrap. Uneendlela ezimbini ongakhetha kuzo: bandakanya yonke iBootstrap, okanye khetha iindawo ozifunayo. Siyayikhuthaza le yokugqibela, nangona sisazi ukuba kukho iimfuno kunye nokuxhomekeka kumacandelo ethu. Kananjalo kuya kufuneka ubandakanye iJavaScript yeeplagi zethu.
Ngolu seto lusendaweni, ungaqala ukulungisa naziphi na izinto eziguquguqukayo zeSass kunye neemephu kweyakho custom.scss
. Ungaqalisa kwakhona ukongeza iinxalenye zeBootstrap phantsi // Optional
kwecandelo njengoko kufuneka. Sicebisa ukuba usebenzise isitaki esipheleleyo sokungenisa bootstrap.scss
kwifayile yethu njengendawo yakho yokuqala.
Ukungagqibeki okuguquguqukayo
Yonke into eguquguqukayo ye-Sass kwi-Bootstrap 4 ibandakanya !default
iflegi ekuvumela ukuba ubhale ngaphezulu ixabiso elimiselweyo le-Sass yakho ngaphandle kokuguqula ikhowudi yemvelaphi ye-Bootstrap. Khuphela kwaye uncamathisele izinto eziguquguqukayo njengoko kufuneka, uguqule amaxabiso azo, kwaye ususe !default
iflegi. Ukuba uguqulo sele lwabelwe, ngoko aluzukwabelwa kwakhona ngamaxabiso angagqibekanga kwiBootstrap.
Uya kufumana uluhlu olupheleleyo lweenguqu zeBootstrap kwi scss/_variables.scss
. Ezinye iinguqu zisetwe ku null
, ezi ziguquguqukayo azikhuphi ipropati ngaphandle kokuba zibhalwe ngaphezulu kuqwalaselo lwakho.
Ukugqithisa okuguquguqukayo ngaphakathi kwefayile ye-Sass efanayo kunokuza ngaphambi okanye emva kokuguquguquka okungagqibekanga. Nangona kunjalo, xa ubeka ngaphezulu kwiifayile zeSass, izinto zakho ezingaphezulu kufuneka zize phambi kokuba ungenise iifayile zeSass zeBootstrap.
Nanku umzekelo otshintsha background-color
kunye color
neyokurhweba <body>
ngaphandle kunye nokuqulunqa i-Bootstrap nge-npm:
Phinda njengoko kuyimfuneko kuyo nayiphi na inguqu kwiBootstrap, kuquka iinketho zehlabathi ezingezantsi.
Iimephu kunye neelophu
I-Bootstrap 4 ibandakanya iimephu ze-Sass ezimbalwa, izibini zexabiso eziphambili ezenza kube lula ukuvelisa iintsapho ze-CSS ehambelanayo. Sisebenzisa iimephu zakwaSass kwimibala yethu, iindawo zokuqhawula igridi, nokunye. Kanye njengezinto eziguquguqukayo ze-Sass, zonke iimephu ze-Sass zibandakanya !default
iflegi kwaye zinokubhalwa ngaphezulu kwaye zandiswe.
Ezinye zeemephu zethu ze-Sass zidityaniswa zibe zingenanto ngokungagqibekanga. Oku kwenzelwa ukuvumela ukwandiswa lula kwemephu ye-Sass enikiweyo, kodwa kuza ngexabiso lokususa izinto kwimephu nzima kancinci.
Guqula imephu
Ukulungisa umbala osele ukhona $theme-colors
kwimephu yethu, yongeza oku kulandelayo kwifayile yakho yesiko leSass:
Yongeza kwimephu
Ukongeza umbala omtsha $theme-colors
, yongeza iqhosha elitsha kunye nexabiso:
Susa kwimephu
Ukususa imibala kwi- $theme-colors
, okanye nayiphi na enye imephu, sebenzisa map-remove
. Qaphela ukuba kufuneka uyifake phakathi kweemfuno zethu kunye nokhetho:
Izitshixo ezifunekayo
I-Bootstrap ithatha ubukho bezitshixo ezithile ngaphakathi kweemephu ze-Sass njengoko besizisebenzisa kwaye sizandise ngokwethu. Njengoko ulungiselela iimephu ezibandakanyiweyo, ungadibana neempazamo apho kusetyenziswa isitshixo semephu ye-Sass ethile.
Umzekelo, sisebenzisa i- primary
, success
kunye danger
nezitshixo ezisuka $theme-colors
kumakhonkco, amaqhosha, kunye nefom yesimo. Ukutshintsha amaxabiso ezi zitshixo kufuneka kungabikho miba, kodwa ukuwasusa kunokubangela imiba yokuhlanganiswa kwe-Sass. Kwezi meko, kuya kufuneka uguqule ikhowudi ye-Sass esebenzisa loo maxabiso.
Imisebenzi
I-Bootstrap isebenzisa imisebenzi emininzi ye-Sass, kodwa iseti encinci kuphela esebenzayo kumxholo jikelele. Sifake imisebenzi emithathu yokufumana ixabiso kwiimephu zemibala:
Oku kukuvumela ukuba ukhethe umbala omnye kwimephu ye-Sass ngendlela onokuthi usebenzise ngayo ukuguquguquka kombala ukusuka kwi-v3.
Kananjalo sinomnye umsebenzi wokufumana umgangatho othile wombala kwimephu $theme-colors
. Amaxabiso amanqanaba angalunganga aya kuwenza lula umbala, ngelixa amanqanaba aphezulu aya kuba mnyama.
Ngokwenza, ungabiza umsebenzi kwaye ugqithise kwiiparamitha ezimbini: igama lombala ukusuka $theme-colors
(umzekelo, iprimary okanye ingozi) kunye nenqanaba lamanani.
Imisebenzi eyongezelelweyo inokongezwa kwixesha elizayo okanye i-Sass yakho yesiko ukwenza imisebenzi yenqanaba leemephu ze-Sass ezongezelelweyo, okanye enye yegeneric ukuba ufuna ukuba ne-verbose ngakumbi.
Umahluko wombala
Umsebenzi owongezelelweyo esiwufakayo kwiBootstrap ngumsebenzi wokuchasa umbala, color-yiq
. Isebenzisa isithuba sombala we-YIQ ukubuyisela ngokuzenzekelayo ukukhanya ( #fff
) okanye mnyama ( #111
) umahluko wombala osekelwe kumbala wesiseko oxeliweyo. Lo msebenzi uluncedo kakhulu kwimixube okanye iilophu apho uvelisa iiklasi ezininzi.
Umzekelo, ukuvelisa iiwotshi zemibala $theme-colors
kwimephu yethu:
Ingasetyenziselwa iimfuno zokuthelekisa enye:
Ungaphinda uchaze umbala osisiseko ngemisebenzi yethu yemephu yombala:
Phuma kwi-SVG
Sisebenzisa escape-svg
umsebenzi ukubaleka <
, >
kunye #
neempawu zeSVG imifanekiso yangasemva. Aba nobumba badinga ukubaleka ukuze banikeze ngokufanelekileyo imifanekiso yangasemva kwi-IE.
Yongeza kwaye uthabathe imisebenzi
Sisebenzisa i add
kunye subtract
nemisebenzi ukusonga umsebenzi weCSS calc
. Eyona njongo yale misebenzi kukuphepha iimpazamo xa ixabiso elithi "unitless" ligqithiselwa 0
kwintetho calc
. Amabinzana afana nala calc(10px - 0)
aya kubuyisela imposiso kuzo zonke iibhrawuza, nangona ichanekile ngokwezibalo.
Umzekelo apho i-calc isemthethweni:
Umzekelo apho i-calc ingasebenziyo:
Iinketho zeSass
Yenza ngokwezifiso i-Bootstrap 4 kunye nefayile yethu eyakhelwe-ngaphakathi eguquguqukayo kwaye uguqule ngokulula izinto ezikhethwa yi-CSS yehlabathi ngezinto ezintsha $enable-*
zeSass. Bhala ngaphezulu ixabiso loguquko kwaye uphinde udibanise npm run test
njengoko kufuneka.
Ungafumana kwaye wenze ezi ziguquguqukayo kwiinketho eziphambili zehlabathi scss/_variables.scss
kwifayile yeBootstrap.
Iyaguquguquka | Imilinganiselo | Inkcazo |
---|---|---|
$spacer |
1rem (ehlala ikho), okanye naliphi na ixabiso > 0 |
Ichaza ixabiso elihlala lihleli le spacer ukuvelisa ngokwenkqubo izixhobo zethu ze spacer . |
$enable-rounded |
true (ehlala ikho) okanyefalse |
Yenza border-radius izimbo ezichazwe kwangaphambili kumacandelo awohlukeneyo. |
$enable-shadows |
true okanye false (okuhlala kukho) |
Yenza box-shadow izimbo ezichazwe kwangaphambili kumacandelo awohlukeneyo. |
$enable-gradients |
true okanye false (okuhlala kukho) |
Yenza iigradient ezichazwe kwangaphambili kusetyenziswa background-image izimbo kwizinto ezahlukeneyo. |
$enable-transitions |
true (ehlala ikho) okanyefalse |
Yenza okuchazwe transition kwangaphambili kumacandelo awohlukeneyo. |
$enable-prefers-reduced-motion-media-query |
true (ehlala ikho) okanyefalse |
Yenza prefers-reduced-motion umbuzo wemidiya , ocinezela oopopayi abathile/utshintsho olusekwe kumkhangeli zincwadi wabasebenzisi/ukhetho lwesixokelelwano esisebenzayo. |
$enable-hover-media-query |
true okanye false (okuhlala kukho) |
Irhoxisiwe |
$enable-grid-classes |
true (ehlala ikho) okanyefalse |
Yenza ukuveliswa kweeklasi zeCSS zesixokelelwano sothungelwano (umzekelo, .container , .row , , .col-md-1 , njl.). |
$enable-caret |
true (ehlala ikho) okanyefalse |
Yenza ipseudo element ikhathalelwe .dropdown-toggle . |
$enable-pointer-cursor-for-buttons |
true (ehlala ikho) okanyefalse |
Yongeza ikhesa "yesandla" kwizinto ezingacinywanga zeqhosha. |
$enable-print-styles |
true (ehlala ikho) okanyefalse |
Yenza izimbo zokuphucula ushicilelo. |
$enable-responsive-font-sizes |
true okanye false (okuhlala kukho) |
Yenza ubungakanani befonti abaphendulayo . |
$enable-validation-icons |
true (ehlala ikho) okanyefalse |
Yenza ii- background-image icon kwizimvo ezibhaliweyo kunye nezinye iifomu zesiko ukulungiselela iimeko zokuqinisekisa. |
$enable-deprecation-messages |
true okanye false (okuhlala kukho) |
Misela true ukubonisa izilumkiso xa usebenzisa nayiphi na imixube eyehliweyo kunye nemisebenzi ecetywayo ukususwa kwi v5 . |
Umbala
Uninzi lwezinto ezahlukeneyo zeBootstrap kunye nezinto eziluncedo zakhiwe ngothotho lwemibala echazwe kwimephu ye-Sass. Le mephu inokulotywa kwi-Sass ukuvelisa ngokukhawuleza uthotho lweesethi zemithetho.
Yonke imibala
Yonke imibala ekhoyo kwi-Bootstrap 4, iyafumaneka njengeenguqu ze-Sass kunye nemephu ye-Sass scss/_variables.scss
kwifayile. Oku kuya kwandiswa kukhupho oluncinci olulandelayo ukongeza i-shades eyongezelelweyo, efana ne- grayscale palette esele siyibandakanyile.
Nantsi indlela onokuzisebenzisa ngayo ezi kwiSass yakho:
Iiklasi eziluncedo zombala zikwakhona ngokusetwa color
kunye background-color
.
Kwixesha elizayo, siza kujolisa ekuboneleleni ngeemephu ze-Sass kunye nezinto eziguquguqukayo zemithunzi yombala ngamnye njengoko senzile ngemibala engwevu engezantsi.
Imibala yomxholo
Sisebenzisa iseti esezantsi yayo yonke imibala ukwenza iphalethi yombala omncinci wokuvelisa izikimu zombala, ezifumanekayo njengeenguqu zeSass kunye nemephu yeSass scss/_variables.scss
kwifayile yeBootstrap.
Iingwevu
Iseti ebanzi yezinto ezingwevu kunye nemephu ye-Sass scss/_variables.scss
kwimithunzi engwevu engaguqukiyo kwiprojekthi yakho yonke. Qaphela ukuba ezi "zingwevu ezipholileyo", ezithandeka kwithoni ehlaza okwesibhakabhaka, kunokuba zibe zingwevu ezingathathi hlangothi.
Ngaphakathi scss/_variables.scss
, uya kufumana iinguqu zemibala zeBootstrap kunye nemephu ye-Sass. Nanku umzekelo $colors
wemephu ye-Sass:
Yongeza, susa, okanye ulungise amaxabiso kwimaphu ukuhlaziya indlela asetyenziswa ngayo kwezinye iindawo ezininzi. Ngelishwa ngeli xesha, asingawo onke amacandelo asebenzisa le mephu ye-Sass. Uhlaziyo lwexesha elizayo luya kuzama ukuphucula oku. Kude kube ngoko, cwangcisa ukusetyenziswa kwezinto ${color}
eziguquguqukayo kunye nale mephu ye-Sass.
Amacandelo
Uninzi lwamacandelo kunye nezinto eziluncedo zeBootstrap zakhiwe @each
ngeelophu eziphindaphindayo kwimephu ye-Sass. Oku kuluncedo kakhulu ekuveliseni ukwahluka kwecandelo ngokwethu $theme-colors
kunye nokudala iiyantlukwano eziphendulayo kwindawo nganye yoqhawulo. Njengoko usenza ngokwezifiso ezi mephu ze-Sass kwaye uphinda uhlanganise, uya kubona ngokuzenzekelayo utshintsho lwakho lubonakaliswe kwezi lophu.
Izilungisi
Uninzi lwamacandelo e-Bootstrap akhiwe ngendlela yeklasi ye-modifier. Oku kuthetha ukuba ubuninzi besimbo buqulethwe kudidi olusisiseko (umzekelo, .btn
) ngelixa ulwahlulo lwesimbo luvalelwe kwiiklasi zesilungisi (umzekelo, .btn-danger
). Ezi klasi zesilungisi zakhiwe $theme-colors
kwimephu ukwenza inani kunye negama leeklasi zethu zesilungisi.
Nantsi imizekelo emibini yendlela esijika ngayo phezu $theme-colors
kwemephu ukwenza izilungisi .alert
zecandelo kunye nazo zonke izinto zethu .bg-*
ezingasemva eziluncedo.
Ukusabela
Ezi lophu zeSass aziphelelanga kwiimephu zemibala, nazo. Unokwenza ukwahluka okuphendulayo kwamacandelo akho okanye izinto eziluncedo. Thatha umzekelo izixhobo zethu zolungelelwaniso lombhalo ophendulayo apho sixuba i- @each
loop $grid-breakpoints
yemephu ye-Sass kunye nombuzo wemidiya uquka.
Ukuba ufuna ukulungisa eyakho $grid-breakpoints
, utshintsho lwakho luya kusebenza kuzo zonke iilophu eziphinda-phindayo phezu kwaloo mephu.
Iinguqu zeCSS
I-Bootstrap 4 ibandakanya malunga neshumi elinesibini leempawu zesiko le-CSS (izinto eziguquguqukayo) kwi-CSS yayo ehlanganisiweyo. Ezi zibonelela ngofikelelo olulula kumaxabiso aqhele ukusetyenziswa njengemibala yomxholo wethu, iindawo zokuqhawuka, kunye nokupakishwa kwefonti esisiseko xa usebenza kuMhloli wesikhangeli sakho, ikhowudi yebhokisi yesanti, okanye iprototyping jikelele.
Izinto eziguquguqukayo ezikhoyo
Nazi izinto eziguquguqukayo esizibandakanyayo (qaphela ukuba :root
iyafuneka). Zifumaneka _root.scss
kwifayile yethu.
Imizekelo
Izinto eziguquguqukayo zeCSS zibonelela ngokuguquguquka okufanayo kwizinto eziguquguqukayo zeSass, kodwa ngaphandle kwesidingo sokuhlanganiswa ngaphambi kokuba zinikezelwe kwisikhangeli. Umzekelo, apha siseta ngokutsha ifonti yephepha lethu kunye nezimbo zekhonkco ezineenguqu zeCSS.
Iinguqu zeBreakpoint
Ngelixa ekuqaleni sasibandakanya ii-breakpoints kwiinguqu zethu ze-CSS (umzekelo, --breakpoint-md
), ezi azixhaswanga kwimibuzo yemidiya , kodwa zisenokusetyenziswa ngaphakathi kweesethi zomthetho kwimibuzo yemidiya. Ezi zantlukwano zebreakpoint zihlala kwi-CSS ehlanganisiweyo yokuhambelana ngasemva xa zinokuthi zisetyenziswe yiJavaScript. Funda ngakumbi kwi-spec .
Nanku umzekelo wento engaxhaswayo:
Kwaye nanku umzekelo wento exhaswayo: