Theming Bootstrap
Enza ngendlela oyifisayo i-Bootstrap 4 ngezinto zethu ezintsha ezakhelwe ngaphakathi ze-Sass ezithandwayo zesitayela somhlaba wonke ukuze uthole itimu elula nezinguquko zengxenye.
Ku-Bootstrap 3, itimu yayiqhutshwa kakhulu ukweqa okuguquguqukayo kokuthi LESS, i-CSS yangokwezifiso, neshidi lesitayela letimu elihlukile esilifake dist
kumafayela ethu. Ngomzamo othile, umuntu angakwazi ukuklama kabusha ngokuphelele ukubukeka kwe-Bootstrap 3 ngaphandle kokuthinta amafayela awumongo. I-Bootstrap 4 inikeza indlela ejwayelekile, kodwa ehluke kancane.
Manje, itimu ifezwa okuguquguqukayo kwe-Sass, amamephu we-Sass, ne-CSS yangokwezifiso. Alisekho ishidi lesitayela letimu elizinikele; esikhundleni salokho, ungakwazi ukunika amandla itimu eyakhelwe ngaphakathi ukuze ungeze ama-gradient, izithunzi, nokuningi.
Sebenzisa umthombo wethu wamafayela e-Sass ukuze uthathe ithuba lokuhlukahluka, amamephu, imiksi, nokuningi.
Noma nini lapho kunokwenzeka, gwema ukulungisa amafayela ayinhloko e-Bootstrap. Kwa-Sass, lokho kusho ukudala eyakho ishidi lesitayela elingenisa i-Bootstrap ukuze ukwazi ukuyilungisa futhi uyinwebe. Uma ucabanga ukuthi usebenzisa umphathi wephakheji njenge-npm, uzoba nesakhiwo sefayela esibukeka kanje:
Uma ulande amafayela ethu omthombo futhi ungasebenzisi umphathi wephakheji, uzofuna ukumisa mathupha into efana naleso sakhiwo, ugcine amafayela omthombo we-Bootstrap ehlukene kwewakho.
Kweyakho custom.scss
, uzongenisa amafayela we-Sass womthombo we-Bootstrap. Unezinketho ezimbili: faka yonke i-Bootstrap, noma khetha izingxenye ozidingayo. Sikhuthaza lokhu okwakamuva, nakuba sazi ukuthi kunezimfuneko ezithile nokuncika kuzo zonke izingxenye zethu. Uzodinga futhi ukufaka i-JavaScript yama-plugin ethu.
Uma lokho kusetha kusendaweni, ungaqala ukulungisa noma yikuphi okuguquguqukayo kwe-Sass namamephu kufayela lakho le- custom.scss
. Ungase futhi uqale ukwengeza izingxenye ze-Bootstrap ngaphansi // Optional
kwesigaba njengoba kudingeka. Siphakamisa ukuthi usebenzise isitaki sokungenisa esigcwele bootstrap.scss
efayelini lethu njengendawo yakho yokuqala.
Konke okuguquguqukayo kwe-Sass ku-Bootstrap 4 kufaka phakathi !default
ifulegi elikuvumela ukuthi ubhale ngaphezulu inani elizenzakalelayo lokuguquguquka ku-Sass yakho ngaphandle kokulungisa ikhodi yomthombo ye-Bootstrap. Kopisha futhi unamathisele okuguquguqukayo njengoba kudingeka, shintsha amanani azo, futhi ukhiphe !default
ifulegi. Uma okuguquguqukayo sekuvele kwabelwe, ngakho-ke ngeke kuphinde kunikezwe amanani azenzakalelayo ku-Bootstrap.
Uzothola uhlu oluphelele lweziguquguquko ze-Bootstrap ku- scss/_variables.scss
.
Ukukhishwa okuguquguqukayo ngaphakathi kwefayela elifanayo le-Sass kungase kufike ngaphambi noma ngemva kokuguquguquka okuzenzakalelayo. Nokho, uma ukhipha kuwo wonke amafayela e-Sass, ukukhipha kwakho kufanele kuze ngaphambi kokuthi ungenise amafayela e-Sass e-Bootstrap.
Nasi isibonelo esishintsha i- kanye background-color
neyokuthi lapho ungenisa futhi uhlanganisa i-Bootstrap nge-npm:color
<body>
Phinda njengoba kudingekile kunoma yikuphi okuguquguqukayo ku-Bootstrap, kuhlanganise nezinketho zomhlaba jikelele ngezansi.
I-Bootstrap 4 ihlanganisa idlanzana lamamephu e-Sass, amapheya enani angukhiye akwenza kube lula ukukhiqiza imindeni ye-CSS ehlobene. Sisebenzisa amamephu e-Sass ngemibala yethu, izindawo zokunqamuka kwegridi, nokuningi. Njengezinto eziguquguqukayo ze-Sass, wonke amamephu akwa-Sass afaka !default
ifulegi futhi angabhalwa phansi futhi andwe.
Amanye amamephu ethu e-Sass ahlanganiswa abe angenalutho ngokuzenzakalelayo. Lokhu kwenzelwa ukuvumela ukunwetshwa okulula kwemephu ye-Sass enikeziwe, kodwa kuza ngezindleko zokwenza ukususa izinto kumephu kube nzima kakhulu.
Ukuze ulungise umbala okhona $theme-colors
kumephu yethu, engeza okulandelayo kufayela lakho langokwezifiso le-Sass:
Ukwengeza umbala omusha ku- $theme-colors
, engeza ukhiye omusha nevelu:
Ukuze ususe imibala ku- $theme-colors
, nanoma iyiphi enye imephu, sebenzisa map-remove
. Qaphela ukuthi kufanele uyifake phakathi kwezimfuneko zethu nezinketho:
I-Bootstrap ithatha ubukhona bokhiye abathile ngaphakathi kwamamephu e-Sass njengoba siwasebenzisile futhi sizinweba thina ngokwethu. Njengoba wenza ngendlela oyifisayo amamephu afakiwe, ungase uhlangabezane namaphutha lapho kusetshenziswa khona ukhiye othile wemephu ye-Sass.
Isibonelo, sisebenzisa i- primary
, success
, kanye danger
nokhiye abavela kuzo $theme-colors
ukuze uthole izixhumanisi, izinkinobho, nezimo zefomu. Ukushintsha amanani alaba khiye akumele kuveze izinkinga, kodwa ukuwasusa kungase kubangele izinkinga zokuhlanganisa i-Sass. Kulezi zimo, uzodinga ukushintsha ikhodi ye-Sass esebenzisa lawo manani.
I-Bootstrap isebenzisa imisebenzi eminingana ye-Sass, kodwa isethi encane kuphela esebenza kungqikithi evamile. Sifake imisebenzi emithathu yokuthola amanani kumamephu ombala:
Lokhu kukuvumela ukuthi ukhethe umbala owodwa kumephu ye-Sass njengokuthi ungasebenzisa kanjani umbala ohlukile ku-v3.
Siphinde sibe nomunye umsebenzi wokuthola izinga elithile lombala $theme-colors
kumephu. Amanani amaleveli angalungile azokhanyisa umbala, kuyilapho amazinga aphezulu ezoba mnyama.
Empeleni, ungabiza umsebenzi bese udlula ngamapharamitha amabili: igama lombala ukusuka $theme-colors
(isb., okuyinhloko noma ingozi) kanye nezinga lezinombolo.
Imisebenzi eyengeziwe ingase yengezwe ngokuzayo noma eyakho i-Sass yangokwezifiso ukuze udale imisebenzi yeleveli yamamephu engeziwe e-Sass, noma ngisho nelinye elijwayelekile uma ufuna ukusho amazwi amaningi.
Umsebenzi owodwa owengeziwe esiwufaka ku-Bootstrap umsebenzi wokugqama kombala, color-yiq
. Isebenzisa isikhala sombala we-YIQ ukubuyisela ngokuzenzakalelayo ukukhanya ( #fff
) noma okumnyama ( #111
) umbala wokugqama osuselwe kumbala wesisekelo oshiwo. Lo msebenzi uwusizo ikakhulukazi kumamiksi noma amaluphu lapho ukhiqiza khona amakilasi amaningi.
Isibonelo, ukwenza ama-swatches ombala $theme-colors
kumephu yethu:
Ingase futhi isetshenziselwe izidingo zokuqhathanisa okukodwa:
Ungaphinda ucacise umbala oyisisekelo ngemisebenzi yethu yemephu yombala:
Enza ngendlela oyifisayo i-Bootstrap 4 ngefayela lethu eliguquguqukayo elakhelwe ngaphakathi futhi uguqule kalula okuthandwayo kwe-CSS yomhlaba wonke ngezinto ezintsha ze- $enable-*
Sass. Khipha inani lokuguquguquka bese uhlanganisa futhi npm run test
njengoba kudingeka.
Ungathola futhi wenze ngendlela oyifisayo lokhu okuguquguqukayo ukuze uthole izinketho ezibalulekile zomhlaba wonke scss/_variables.scss
kufayela le-Bootstrap.
Iyaguquguquka | Amanani | Incazelo |
---|---|---|
$spacer |
1rem (okuzenzakalelayo), nanoma yiliphi inani > 0 |
Icacisa inani elizenzakalelayo le-spacer ukukhiqiza ngokuhlelekile izinsiza zethu ze-spacer . |
$enable-rounded |
true (okuzenzakalelayo) nomafalse |
Inika amandla border-radius izitayela ezichazwe ngaphambilini ezingxenyeni ezihlukahlukene. |
$enable-shadows |
true noma false (okuzenzakalelayo) |
Inika amandla box-shadow izitayela ezichazwe ngaphambilini ezingxenyeni ezihlukahlukene. |
$enable-gradients |
true noma false (okuzenzakalelayo) |
Inika amandla ama-gradient achazwe ngaphambilini background-image ngezitayela ezingxenyeni ezihlukahlukene. |
$enable-transitions |
true (okuzenzakalelayo) nomafalse |
Inika amandla transition ama-s achazwe ngaphambilini ezingxenyeni ezihlukahlukene. |
$enable-hover-media-query |
true noma false (okuzenzakalelayo) |
Kwehlisiwe |
$enable-grid-classes |
true (okuzenzakalelayo) nomafalse |
Inika amandla ukukhiqizwa kwamakilasi e-CSS kusistimu yegridi (isb, .container , .row , .col-md-1 , njll.). |
$enable-caret |
true (okuzenzakalelayo) nomafalse |
Inika amandla i-pseudo element caret ku- .dropdown-toggle . |
$enable-print-styles |
true (okuzenzakalelayo) nomafalse |
Inika amandla izitayela zokuthuthukisa ukuphrinta. |
Izingxenye eziningi nezinsiza ezihlukahlukene ze-Bootstrap zakhiwe ngochungechunge lwemibala echazwe kumephu ye-Sass. Le mephu ingafakwa ku-Sass ukuze ikhiqize ngokushesha uchungechunge lwamasethi emithetho.
Yonke imibala etholakala ku-Bootstrap 4, iyatholakala njengezinto eziguquguqukayo ze-Sass kanye nemephu ye-Sass scss/_variables.scss
efayeleni. Lokhu kuzonwetshwa ekukhishweni okuncane okulandelayo ukuze kwengezwe ama-shades engeziwe, afana nephalethi ye-grayscale esesivele siyifakile.
Nansi indlela ongazisebenzisa ngayo lezi ku-Sass yakho:
Amakilasi okusetshenziswa kwemibala nawo ayatholakala ukuze amiswe color
futhi background-color
.
Ngokuzayo, sizohlose ukuhlinzeka ngamamephu we-Sass nokuguquguquka kwemibala yombala ngamunye njengoba senzile ngemibala empunga engezansi.
Sisebenzisa isethi engaphansi yayo yonke imibala ukuze sakhe iphalethi yombala encane ukuze sikhiqize izikimu zombala, ezitholakala futhi njengeziguquguqukayo ze-Sass kanye nemephu ye-Sass scss/_variables.scss
kufayela le-Bootstraps.
Isethi enwetshiwe yokuhlukahluka okumpunga kanye nemephu ye-Sass scss/_variables.scss
ukuze uthole imithunzi engaguquki yokumpunga kuyo yonke iphrojekthi yakho.
Ngaphakathi scss/_variables.scss
, uzothola okuguquguqukayo kombala kwe-Bootstrap kanye nemephu ye-Sass. Nasi isibonelo $colors
semephu ye-Sass:
Engeza, susa, noma lungisa amanani ngaphakathi kwemephu ukuze ubuyekeze indlela asetshenziswa ngayo kwezinye izingxenye eziningi. Ngeshwa ngalesi sikhathi, akuzona zonke izingxenye ezisebenzisa le mephu ye-Sass. Izibuyekezo zesikhathi esizayo zizolwela ukuthuthukisa kulokhu. Kuze kube yileso sikhathi, hlela ukusebenzisa ${color}
okuguquguqukayo kanye nale mephu ye-Sass.
Izingxenye eziningi nezinsiza ze-Bootstrap zakhiwe @each
ngamalophu aphindaphindayo phezu kwemephu ye-Sass. Lokhu kusiza kakhulu ekukhiqizeni okuhlukile kwengxenye yethu $theme-colors
nokudala okuhlukile okusabelayo kwephuzu ngalinye lokuhlukana. Njengoba wenza ngendlela oyifisayo lawa mamephu we-Sass futhi uhlanganisa futhi, uzobona ngokuzenzakalela izinguquko zakho ziboniswa kulawa maluphu.
Izingxenye eziningi ze-Bootstrap zakhiwe ngendlela yekilasi le-base-modifier. Lokhu kusho ukuthi inqwaba yesitayela iqukethwe kusigaba sesisekelo (isb, .btn
) kuyilapho ukuhluka kwesitayela kuphelele kumakilasi okulungisa (isb, .btn-danger
). Lezi zigaba zokuguqula zakhiwe kusukela $theme-colors
kumephu ukuze kwenziwe ngendlela oyifisayo inombolo negama lamakilasi ethu okulungisa.
Nazi izibonelo ezimbili zokuthi singena kanjani phezu $theme-colors
kwemephu ukuze sikhiqize izilungisi .alert
zengxenye kanye nazo zonke .bg-*
izinsiza zethu ezingemuva.
Lawa ma-loops akwa-Sass awakhawulelwe kumamephu anemibala, nawo. Ungakwazi futhi ukukhiqiza ukuhlukahluka okusabelayo kwezingxenye zakho noma izinsiza. Thatha isibonelo izinsiza zethu zokuqondanisa umbhalo osabelayo lapho sixuba @each
iluphu $grid-breakpoints
yemephu ye-Sass kanye nombuzo wemidiya.
Uma kwenzeka udinga ukulungisa $grid-breakpoints
, izinguquko zakho zizosebenza kuwo wonke ama-loops aphindaphindayo kuleyo mephu.
I-Bootstrap 4 ihlanganisa cishe izingxenye ezimbili nambili zangokwezifiso ze-CSS (okuguquguqukayo) ku-CSS yayo ehlanganisiwe. Lokhu kunikeza ukufinyelela okulula kumanani asetshenziswa kakhulu njengemibala yethu yetimu, ama-breakpoint, nezitaki zefonti eziyinhloko lapho usebenza Kumhloli wesiphequluli sakho, ikhodi yesihlabathi, noma i-prototyping evamile.
Nazi izinto eziguquguqukayo esizihlanganisayo (qaphela ukuthi :root
kuyadingeka). Atholakala _root.scss
kufayela lethu.
Okuguquguqukayo kwe-CSS kunikeza ukuguquguquka okufanayo kokuguquguqukayo kwe-Sass, kodwa ngaphandle kwesidingo sokuhlanganisa ngaphambi kokuthi kunikezwe isiphequluli. Isibonelo, lapha sisetha kabusha ifonti yekhasi lethu nezitayela zokuxhumanisa neziguquguqukayo ze-CSS.
Nakuba ekuqaleni sifake ama-breakpoint ezinguqukweni zethu ze-CSS (isb, --breakpoint-md
), lezi azisekelwe emibuzweni yemidiya , kodwa zingasetshenziswa ngaphakathi kwezimiso zemithetho emibuzweni yemidiya. Lezi zinguquko ze-breakpoint zihlala ku-CSS ehlanganisiwe ukuze zihambisane nemuva uma zingasetshenziswa yi-JavaScript. Funda kabanzi ku-spec.
Nasi isibonelo salokho okungasekelwe:
Futhi nasi isibonelo salokho okusekelwayo: