Theming Bootstrap
Gadzirisa Bootstrap 4 neyedu itsva yakavakirwa-muSass machinjiro epasirese masitaera aunofarira kuti zvive nyore theming uye chikamu chekuchinja.
MuBootstrap 3, theming yainyanya kufambiswa nekusiyana-siyana muLESS, tsika CSS, uye yakaparadzana theme stylesheet yatakaisa dist
mumafaira edu. Nekumwe kuedza, munhu anogona kugadzirisa zvachose chitarisiko cheBootstrap 3 pasina kubata mafaera epakati. Bootstrap 4 inopa yakajairika, asi yakati siyanei maitiro.
Ikozvino, theming inopedzwa neSass akasiyana, Sass mepu, uye tsika CSS. Hapasisina yakatsaurirwa theme stylesheet; pachinzvimbo, unogona kugonesa yakavakirwa-mukati theme kuti uwedzere gradients, mimvuri, uye nezvimwe.
Shandisa yedu sosi mafaera eSass kutora mukana wekusiyana, mepu, musanganiswa, nezvimwe.
Pese pazvinogoneka, dzivirira kugadzirisa mafaira eBootstrap. Kune Sass, zvinoreva kugadzira yako wega stylesheet inopinza Bootstrap kuti ugone kuigadzirisa nekuiwedzera. Kufungidzira kuti uri kushandisa pasuru maneja senge npm, iwe unenge uine faira chimiro chinotaridzika seizvi:
Kana iwe wakadhawunirodha yedu sosi mafaera uye usingashandise pasuru maneja, iwe unenge uchida kumisikidza nemaoko chimwe chinhu chakafanana neiyo chimiro, uchichengeta Bootstrap's sosi mafaera akasiyana kubva kune ako.
Mune yako custom.scss
, iwe unopinza Bootstrap's source Sass mafaera. Iwe une mbiri sarudzo: sanganisira ese eBootstrap, kana tora zvikamu zvaunoda. Tinokurudzira vekupedzisira, asi ziva kuti pane zvimwe zvinodiwa uye zvinotsamira pazvikamu zvedu. Iwe zvakare unozofanirwa kusanganisira imwe JavaScript yemapulagi edu.
Nekuseta ikoko munzvimbo, unogona kutanga kugadzirisa chero maSass akasiyana uye mepu mune yako custom.scss
. Iwe unogona zvakare kutanga kuwedzera zvikamu zveBootstrap pasi // Optional
pechikamu sezvinodiwa. Isu tinopa zano kushandisa iyo yakazara yekupinza stack kubva bootstrap.scss
kufaira redu senzvimbo yako yekutanga.
Yese Sass inosiyana muBootstrap 4 inosanganisira !default
mureza inokubvumidza kuti uwedzere kukosha kweiyo dhizaini muSass yako pasina kugadzirisa Bootstrap's source code. Kopira uye unamate zvinosiyana sezvinodiwa, shandura maitiro avo, uye bvisa !default
mureza. Kana shanduko yakatopihwa, saka haizopihwazve neiyo default tsika muBootstrap.
Inosiyana-siyana inodarika mukati meiyo Sass faira inogona kuuya isati yasvika kana mushure mekusarudzika. Nekudaro, kana uchipfuura mafaera eSass, ako epamusoro anofanira kuuya usati waunza maBootstrap's Sass mafaera.
Heino muenzaniso unoshandura iyo background-color
uye color
yeiyo <body>
kana uchipinza uye kunyora Bootstrap kuburikidza npm:
Dzokorora sezvinodiwa kune chero shanduko muBootstrap, kusanganisira sarudzo dzepasirese pazasi.
Bootstrap 4 inosanganisira mashoma emamepu eSass, akakosha mapeya anoita kuti zvive nyore kugadzira mhuri dzeCSS ine hukama. Isu tinoshandisa mamepu eSass kune edu mavara, grid breakpoints, nezvimwe. Sezvakangoita maSass akasiyana, ese maSass mepu anosanganisira !default
mureza uye anogona kudhindwa nekuwedzerwa.
Mamwe emamepu edu eSass anobatanidzwa kuita asina chinhu nekukasira. Izvi zvinoitirwa kubvumira kuwedzera kuri nyore kwemepu yeSass yakapihwa, asi zvinouya nemubhadharo wekugadzira kubvisa zvinhu kubva pamepu kuoma zvishoma.
Kuti ugadzirise ruvara rwuripo $theme-colors
pamepu yedu, wedzera zvinotevera kune yako tsika Sass faira:
Kuti uwedzere ruvara rutsva ku $theme-colors
, wedzera kiyi nyowani uye kukosha:
Kubvisa mavara kubva $theme-colors
, kana chero imwe mepu, shandisa map-remove
:
Bootstrap inotora kuvapo kwemamwe makiyi mukati meSass mepu sezvataishandisa uye kuwedzera iwo pachedu. Sezvo iwe uchigadzirisa mamepu anosanganisirwa, unogona kusangana nezvikanganiso apo chaiyo Sass mepu kiyi iri kushandiswa.
Semuenzaniso, isu tinoshandisa iyo primary
, success
, uye danger
makiyi kubva $theme-colors
kune zvinongedzo, mabhatani, uye fomu nyika. Kutsiva kukosha kwemakiyi aya hakufanire kuratidza nyaya, asi kubvisa kunogona kukonzera Sass kuunganidza nyaya. Muzviitiko izvi, iwe unozofanirwa kugadzirisa iyo Sass kodhi inoshandisa iwo maitiro.
Bootstrap inoshandisa akati wandei maSass mabasa, asi chete subset inoshanda kune general theming. Isu takasanganisira mabasa matatu ekutora kukosha kubva kumamepu emavara:
Izvi zvinokutendera kuti usarudze rumwe ruvara kubva pamepu yeSass zvakanyanya semashandisiro aungaita ruvara rwakasiyana kubva kuv3.
Isu tine zvakare rimwe basa rekuwana imwe nhanho yeruvara kubva $theme-colors
pamepu. Negative level values inorerutsa ruvara, ukuwo mazinga epamusoro achisviba.
Mukuita, iwe unodaidza basa racho uye wopfuura muzvikamu zviviri: zita reruvara kubva $theme-colors
(semuenzaniso, chekutanga kana njodzi) uye nhamba yenhamba.
Mamwe mabasa anogona kuwedzerwa mune ramangwana kana yako tsika Sass kugadzira nhanho mashandiro emamwe mamepu eSass, kana generic kana iwe uchida kuve wakanyanya verbose.
Rimwe basa rekuwedzera ratinosanganisa muBootstrap ibasa rekusiyanisa ruvara, color-yiq
. Inoshandisa iyo YIQ nzvimbo yemavara kuti idzorere otomatiki mwenje ( #fff
) kana yakasviba ( #111
) musiyano weruvara unoenderana neyakatsanangurwa base color. Iri basa rinonyanya kubatsira kumamikisi kana zvishwe pauri kugadzira akawanda makirasi.
Semuenzaniso, kugadzira mavara emavara kubva $theme-colors
pamepu yedu:
Inogona zvakare kushandiswa kune imwe-off mutsauko zvinodiwa:
Iwe unogona zvakare kutsanangura ruvara rwepasi nemepu yedu yemavara mabasa:
Gadzirisa Bootstrap 4 neyedu yakavakirwa-mukati dhizaini faira uye shandura zviri nyore zvepasirese CSS zvaunofarira nezvitsva $enable-*
zveSass. Pindura kukosha kwechinhu uye wobatanidza pamwe npm run test
chete sezvinodiwa.
Iwe unogona kuwana uye kugadzirisa aya machinjiro kune akakosha epasi rose sarudzo _variables.scss
mufaira redu.
Variable | Values | Tsanangudzo |
---|---|---|
$spacer |
1rem (default), kana chero kukosha> 0 |
Inodoma iyo default spacer kukosha kuti igadzire yedu spacer utilities . |
$enable-rounded |
true (default) kanafalse |
Inogonesa border-radius zvitaera zvakafanotsanangurwa pazvikamu zvakasiyana. |
$enable-shadows |
true kana false (default) |
Inogonesa box-shadow zvitaera zvakafanotsanangurwa pazvikamu zvakasiyana. |
$enable-gradients |
true kana false (default) |
Inogonesa kufanotsanangurwa gradients kuburikidza background-image nezvitaera pane akasiyana mazvikamu. |
$enable-transitions |
true (default) kanafalse |
Inogonesa predefined transition s pazvikamu zvakasiyana. |
$enable-hover-media-query |
true kana false (default) |
Yakarambwa |
$enable-grid-classes |
true (default) kanafalse |
Inogonesa kugadzirwa kweCSS makirasi egidhi system (semuenzaniso, .container , .row , .col-md-1 , nezvimwewo). |
$enable-caret |
true (default) kanafalse |
Inogonesa pseudo element caret pa .dropdown-toggle . |
$enable-print-styles |
true (default) kanafalse |
Inogonesa masitaera ekugonesa kudhinda. |
Zvizhinji zveBootstrap zvakasiyana-siyana zvikamu uye zvishandiso zvinovakwa kuburikidza neakatevedzana emavara anotsanangurwa mumepu yeSass. Iyi mepu inogona kuvharirwa muSass kuti ikurumidze kugadzira nhevedzano yemitemo.
Ese mavara anowanikwa muBootstrap 4, anowanikwa seSass akasiyana uye mepu yeSass scss/_variables.scss
mufaira redu. Izvi zvichawedzerwa pane anotevera madiki ekuburitswa kuti awedzere mamwe mimvuri, senge greyscale palette yatinotobatanidza .
Heano maitiro aungashandisa aya muSass yako:
Makirasi ekushandisa mavara anowanikwawo pakuseta color
uye background-color
.
Mune ramangwana, isu tichavavarira kupa maSass mamepu uye akasiyana emhando dzemavara ega ega sezvatakaita ne grayscale mavara pazasi.
Isu tinoshandisa subset yemavara ese kugadzira diki diki pendi yekugadzira mavara zvirongwa, inowanikwawo seSass zvinosiyana uye mepu yeSass scss/_variables.scss
mufaira redu.
Iyo yakawedzera seti yegrey akasiyana uye mepu yeSass mune scss/_variables.scss
inowirirana mimvuri yegrey pane yako purojekiti.
Mukati me _variables.scss
, iwe unowana yedu mavara akasiyana uye Sass mepu. Heino muenzaniso $colors
weSass mepu:
Wedzera, bvisa, kana shandura kukosha mukati memepu kuti uvandudze mashandisirwo aanoitwa mune zvimwe zvikamu zvakawanda. Nehurombo panguva ino, hazvisi zvese zvikamu zvinoshandisa iyi mepu yeSass. Zvidzoreso zveramangwana zvichaedza kuvandudza pane izvi. Kusvika panguva iyoyo, ronga pakushandisa ${color}
zvinosiyana uye iyi mepu yeSass.
Zvizhinji zvezvinhu zveBootstrap uye zvinoshandiswa zvinovakwa @each
nezvishwe zvinodzokorora pamusoro pemepu yeSass. Izvi zvinonyanya kubatsira pakugadzira mutsauko wechikamu neyedu $theme-colors
uye kugadzira anopindura akasiyana ega ega breakpoint. Sezvo iwe uchigadzirisa aya mamepu eSass uye kudzoreredza, iwe unozoona otomatiki shanduko dzako dzichiratidzwa muzvishwe izvi.
Zvizhinji zvezvinhu zveBootstrap zvakavakwa ne base-modifier kirasi maitiro. Izvi zvinoreva kuti huwandu hwemataera huri mukirasi yepasi (semuenzaniso, .btn
) nepo masitaera akasiyana achingogumira kumakirasi ekugadzirisa (semuenzaniso, .btn-danger
). Aya makirasi ekugadzirisa akavakwa kubva $theme-colors
pamepu kuti agadzirise nhamba uye zita remakirasi edu ekugadzirisa.
Heino mienzaniso miviri yemabatiro atinoita pamusoro $theme-colors
pemepu kuti tigadzire ma modifiers kuchikamu .alert
uye zvese zvedu .bg-*
zvemashure zvinoshandiswa.
Aya maSass loops haana kugumira kumamepu emavara, kana. Iwe unogona zvakare kugadzira inopindura misiyano yezvikamu zvako kana zvishandiso. Tora semuenzaniso yedu inopindura mameseji ekugadzirisa mameseji kwatinosanganisa @each
loop $grid-breakpoints
yemepu yeSass nemubvunzo wenhau unosanganisira.
Kana iwe uchifanira kugadzirisa yako $grid-breakpoints
, shanduko dzako dzinoshanda kune ese zvishwe zvinodzokorora pamusoro pemepu iyoyo.
Bootstrap 4 inosanganisira anenge gumi nemaviri eCSS tsika zvivakwa (zvinosiyana) mune iyo yakaumbwa CSS. Izvi zvinopa nyore kuwana kune anowanzo shandiswa kukosha senge yedu theme mavara, mabreakpoints, uye ekutanga font stacks paunenge uchishanda mubrowser's Inspector, kodhi sandbox, kana general prototyping.
Heano mavara atinosanganisa (ona kuti izvo :root
zvinodiwa). Anowanikwa _root.scss
mufaira redu.
CSS zvinosiyana zvinopa kuchinjika kwakafanana kune maSass akasiyana, asi pasina kudikanwa kwekubatanidza isati yapihwa kune browser. Semuenzaniso, pano tiri kusetazve mafonti epeji redu uye masitaera ekubatanidza ane CSS zvinosiyana.
Iwe unogona zvakare kushandisa yedu breakpoint akasiyana mune yako midhiya mibvunzo: