Bootstrap
Hindura Bootstrap 4 hamwe nuburyo bushya bwubatswe muri Sass ihindagurika kumiterere yisi yose ukunda kubintu byoroshye nibihinduka.
Intangiriro
Muri Bootstrap 3, insanganyamatsiko ahanini yatwarwaga nimpinduka zirenga muri LESS, CSS yihariye, hamwe nurupapuro rwihariye rwimiterere twashizemo muri dist
dosiye zacu. Hamwe nimbaraga, umuntu yashoboraga guhindura rwose isura ya Bootstrap 3 idakora kuri dosiye yibanze. Bootstrap 4 itanga uburyo bumenyerewe, ariko butandukanye gato.
Noneho, insanganyamatsiko irangizwa nimpinduka za Sass, ikarita ya Sass, hamwe na CSS yihariye. Nta yindi nsanganyamatsiko yihariye; ahubwo, urashobora gukora insanganyamatsiko yubatswe kugirango wongere gradients, igicucu, nibindi byinshi.
Sass
Koresha isoko yacu Sass dosiye kugirango ukoreshe impinduka, ikarita, ivanga, nibindi byinshi. Mubyubaka byacu twongereye Sass kuzenguruka neza kuri 6 (muburyo busanzwe ni 5) kugirango twirinde ibibazo hamwe no kuzenguruka kwa mushakisha.
Imiterere ya dosiye
Igihe cyose bishoboka, irinde guhindura dosiye yibanze ya Bootstrap. Kuri Sass, bivuze gukora urupapuro rwawe bwite rutumiza Bootstrap kugirango ubashe guhindura no kuyagura. Dufate ko ukoresha paketi umuyobozi nka npm, uzagira imiterere ya dosiye isa nkiyi:
Niba warakuyeho amadosiye yinkomoko yacu kandi ukaba udakoresha pake yumuyobozi, uzakenera gushiraho intoki ikintu gisa nkiyo miterere, ukagumana dosiye yinkomoko ya Bootstrap itandukanye niyanyu.
Kuzana ibicuruzwa
Muriwe custom.scss
, uzatumiza inkomoko ya Bootstrap ya Sass dosiye. Ufite amahitamo abiri: shyiramo Bootstrap yose, cyangwa hitamo ibice ukeneye. Turashishikariza aba nyuma, nubwo mumenye ko hari ibyo dusabwa hamwe nubwishingizi mubice byacu. Uzakenera kandi gushyiramo JavaScript ya plugins zacu.
Hamwe nuburyo bwashyizweho, urashobora gutangira guhindura icyaricyo cyose cya Sass hamwe namakarita yawe custom.scss
. Urashobora kandi gutangira kongeramo ibice bya Bootstrap munsi yicyiciro // Optional
nkuko bikenewe. Turasaba ko dukoresha ibicuruzwa byuzuye biva muri bootstrap.scss
dosiye yacu nkintangiriro.
Impinduka zisanzwe
Buri Sass ihinduka muri Bootstrap 4 ikubiyemo !default
ibendera ryemerera kurenga agaciro gasanzwe kahinduwe muri Sass yawe bwite udahinduye code ya Bootstrap. Gukoporora no gukata impinduka nkuko bikenewe, uhindure indangagaciro, kandi ukureho !default
ibendera. Niba impinduka zimaze gutangwa, ntabwo izongera kugenwa nagaciro gasanzwe muri Bootstrap.
Uzasangamo urutonde rwuzuye rwibihinduka bya Bootstrap muri scss/_variables.scss
.
Ibihinduka birenze muri dosiye imwe ya Sass irashobora kuza mbere cyangwa nyuma yimiterere ihindagurika. Ariko, mugihe urengereye dosiye ya Sass, ibirenga byawe bigomba kuza mbere yuko winjiza dosiye ya Sass ya Bootstrap.
Dore urugero ruhindura i background-color
na color
kuri <body>
iyo mugihe cyo gutumiza no gukusanya Bootstrap ukoresheje npm:
Subiramo nkibikenewe kubihinduka byose muri Bootstrap, harimo amahitamo yisi yose hepfo.
Ikarita
Bootstrap 4 ikubiyemo amakarita ya Sass yintoki, ibyingenzi byingenzi byoroha kubyara imiryango ya CSS ifitanye isano. Dukoresha amakarita ya Sass kumabara yacu, grid point ya point, nibindi byinshi. Nka Sass ihinduka, amakarita yose ya Sass arimo !default
ibendera kandi arashobora kurengerwa no kwagurwa.
Amwe mu makarita yacu ya Sass yahujwe nubusa kubusa. Ibi bikorwa kugirango yemere kwaguka byoroshye ikarita ya Sass yatanzwe, ariko iza ku kiguzi cyo gukora ibintu ku ikarita bigoye cyane.
Hindura ikarita
Guhindura ibara risanzwe kurikarita yacu $theme-colors
, ongeraho ibikurikira muri dosiye yawe ya Sass:
Ongera ku ikarita
Kongera ibara rishya kuri $theme-colors
, ongeramo urufunguzo rushya nagaciro:
Kura ku ikarita
Kuraho amabara $theme-colors
, cyangwa indi karita iyo ari yo yose, koresha map-remove
. Menya neza ko ugomba kubishyira hagati y'ibyo dusabwa n'amahitamo:
Urufunguzo rusabwa
Bootstrap ifata ko hari urufunguzo rwihariye mu ikarita ya Sass nkuko twakoresheje kandi twagura ubwacu. Mugihe uhinduye amakarita arimo, urashobora guhura namakosa aho urufunguzo rwikarita ya Sass rukoreshwa.
Kurugero, dukoresha i primary
,, success
na danger
urufunguzo kuva kumurongo $theme-colors
, buto, na form leta. Gusimbuza indangagaciro zuru rufunguzo ntibigomba kwerekana ibibazo, ariko kubikuraho bishobora gutera ibibazo byo gukusanya Sass. Muri ibi bihe, uzakenera guhindura code ya Sass ikoresha izo ndangagaciro.
Imikorere
Bootstrap ikoresha ibikorwa byinshi bya Sass, ariko igice kimwe gusa kirakoreshwa kumutwe rusange. Twashizemo imikorere itatu yo kubona indangagaciro kuva ku ikarita y'amabara:
Ibi biragufasha guhitamo ibara rimwe kurikarita ya Sass nkukuntu wakoresha ibara rihinduka kuva v3.
Dufite kandi ikindi gikorwa cyo kubona urwego runaka rwamabara kurikarita $theme-colors
. Urwego rubi indangagaciro zizorohereza ibara, mugihe urwego rwo hejuru ruzijimye.
Mu myitozo, wahamagara imikorere hanyuma ukanyuza mubice bibiri: izina ryibara kuva $theme-colors
(urugero, ibanze cyangwa akaga) nurwego rwumubare.
Ibikorwa byinyongera birashobora kongerwaho mugihe kizaza cyangwa kugiti cyawe Sass kugirango ukore ibikorwa byurwego rwikarita yinyongera ya Sass, cyangwa nibisanzwe niba ushaka kuba inshinga nyinshi.
Itandukaniro ryamabara
Igikorwa kimwe cyinyongera dushyira muri Bootstrap nigikorwa cyo gutandukanya ibara , color-yiq
. Ikoresha ibara ryamabara YIQ kugirango ihite isubiza urumuri ( #fff
) cyangwa umwijima ( #111
) rutandukanye rushingiye kumabara yibanze. Iyi mikorere ni ingirakamaro cyane cyane kuvanga cyangwa kuzenguruka aho ubyara ibyiciro byinshi.
Kurugero, kubyara amabara yaturutse ku $theme-colors
ikarita yacu:
Irashobora kandi gukoreshwa muburyo bumwe butandukanye:
Urashobora kandi kwerekana ibara shingiro hamwe nibikorwa byikarita yamabara:
Amahitamo ya Sass
Hindura Bootstrap 4 hamwe na fayili yacu yubatswe yihariye kandi uhindure byoroshye CSS yisi yose hamwe nibihinduka bishya bya $enable-*
Sass. Kurenga agaciro k'ibihinduka hanyuma usubiremo npm run test
nkuko bikenewe.
Urashobora kubona no guhitamo ibyo bihinduka kubintu byingenzi byingenzi byisi muri scss/_variables.scss
dosiye ya Bootstrap.
Birahinduka | Indangagaciro | Ibisobanuro |
---|---|---|
$spacer |
1rem (Mburabuzi), cyangwa agaciro ako ari ko kose> 0 |
Kugaragaza agaciro gasanzwe kamaro kugirango gahunda itange umusaruro wibikoresho byacu . |
$enable-rounded |
true (Mburabuzi) cyangwafalse |
Gushoboza uburyo bwateganijwe mbere border-radius kubintu bitandukanye. |
$enable-shadows |
true cyangwa false (Mburabuzi) |
Gushoboza uburyo bwateganijwe mbere box-shadow kubintu bitandukanye. |
$enable-gradients |
true cyangwa false (Mburabuzi) |
Gushoboza gradients zateganijwe binyuze background-image muburyo butandukanye. |
$enable-transitions |
true (Mburabuzi) cyangwafalse |
Gushoboza transition s byateganijwe mbere kubice bitandukanye. |
$enable-prefers-reduced-motion-media-query |
true (Mburabuzi) cyangwafalse |
Gushoboza prefers-reduced-motion itangazamakuru kubaza , rihagarika animasiyo / inzibacyuho zishingiye kuri mushakisha y'abakoresha / sisitemu y'imikorere. |
$enable-hover-media-query |
true cyangwa false (Mburabuzi) |
Gutesha agaciro |
$enable-grid-classes |
true (Mburabuzi) cyangwafalse |
Gushoboza ibisekuru bya CSS ya sisitemu ya gride (urugero ,,,, .container nibindi .row ) .col-md-1 . |
$enable-caret |
true (Mburabuzi) cyangwafalse |
Gushoboza pseudo element caret kuri .dropdown-toggle . |
$enable-print-styles |
true (Mburabuzi) cyangwafalse |
Gushoboza uburyo bwo guhitamo icapiro. |
$enable-validation-icons |
true (Mburabuzi) cyangwafalse |
Gushoboza background-image amashusho mumyandikire yinyandiko hamwe nuburyo bwihariye bwo kwemeza leta. |
Ibara
Byinshi mubintu bitandukanye bya Bootstrap nibikorwa byubatswe binyuze murukurikirane rwamabara asobanurwa mukarita ya Sass. Ikarita irashobora kuzunguruka muri Sass kugirango byihute kubyara urukurikirane rw'amategeko.
Amabara yose
Amabara yose aboneka muri Bootstrap 4, arahari nkibihinduka bya Sass n'ikarita ya Sass muri scss/_variables.scss
dosiye. Ibi bizagurwa mugihe gito gisohotse kugirango hongerwemo igicucu, cyane nka palette palette dusanzwe dushyiramo.
Dore uko ushobora gukoresha ibi muri Sass yawe:
Amabara yingirakamaro yamasomo nayo arahari mugushiraho color
na background-color
.
Mugihe kizaza, tuzagerageza gutanga amakarita ya Sass nibihinduka kubicucu bya buri bara nkuko twabikoze hamwe namabara ya graycale hepfo.
Amabara yibanze
Dukoresha igice cyamabara yose kugirango dukore palette ntoya yo kubyara amabara, nayo iraboneka nkibihinduka bya Sass hamwe nikarita ya Sass muri scss/_variables.scss
dosiye ya Bootstraps.
Icyatsi
Ikirangantego cyagutse cyimyenda ihindagurika hamwe nikarita ya Sass scss/_variables.scss
kugirango igaragaze igicucu cyumuhondo hejuru yumushinga wawe. Menya ko ibyo ari “ibara ryiza”, ryerekeza ku ijwi ryoroshye ry'ubururu, aho kuba ibara ridafite aho ribogamiye.
Imbere scss/_variables.scss
, uzasangamo ibara rya Bootstrap hamwe namakarita ya Sass. Dore urugero $colors
rw'ikarita ya Sass:
Ongeraho, ukureho, cyangwa uhindure indangagaciro mukarita kugirango uvugurure uko zikoreshwa mubindi bice byinshi. Kubwamahirwe muriki gihe, ntabwo buri kintu cyose gikoresha ikarita ya Sass. Ibihe bizaza bizaharanira kunoza ibi. Kugeza icyo gihe, teganya gukoresha ${color}
impinduka n'iyi karita ya Sass.
Ibigize
Byinshi mubice bya Bootstrap nibikoresho byingirakamaro byubatswe hamwe @each
nibisubirwamo hejuru yikarita ya Sass. Ibi bifasha cyane cyane kubyara ibice bigize ibice byacu $theme-colors
no gukora impinduka zishubije kuri buri gice. Mugihe uhinduye amakarita ya Sass hanyuma ukayasubiramo, uzahita ubona impinduka zawe zigaragara muriyi mirongo.
Abahindura
Byinshi mubice bya Bootstrap byubatswe hamwe na base-modifier class approach. Ibi bivuze ko igice kinini cyimyandikire gikubiye mubyiciro fatizo (urugero, .btn
) mugihe imiterere itandukanye igarukira kumasomo yo guhindura (urugero, .btn-danger
). Aya masomo yo guhindura yubatswe kuva ku $theme-colors
ikarita kugirango uhindure umubare nizina ryibyiciro byacu byo guhindura.
Hano hari ingero ebyiri zuburyo twazengurutse $theme-colors
ikarita kugirango tubyare impinduka .alert
mubice byose hamwe ninyuma yibikorwa byacu byose .bg-*
.
Igisubizo
Utuzingo twa Sass ntabwo tugarukira ku ikarita y'amabara, haba. Urashobora kandi kubyara itandukaniro ryibisubizo byibigize cyangwa ibikorwa byawe. Fata nkurugero rwibisubizo byingirakamaro byingirakamaro aho tuvanga ikarita yikarita @each
ya $grid-breakpoints
Sass hamwe nibibazo byitangazamakuru birimo.
Mugihe ukeneye guhindura ibyawe $grid-breakpoints
, impinduka zawe zizakoreshwa kumuzingo wose uzenguruka kurikarita.
Impinduka za CSS
Bootstrap 4 ikubiyemo ibintu bibiri bya CSS byihariye (variable) muri CSS yakozwe. Ibi bitanga uburyo bworoshye bwo kubona indangagaciro zikoreshwa nkamabara yinsanganyamatsiko, gucamo, hamwe nimyandikire yibanze mugihe ukora muri Inspecteur ya mushakisha yawe, agasanduku kode, cyangwa prototyping rusange.
Ibihinduka biboneka
Dore impinduka dushyiramo (menya ko :root
ibisabwa). Biri muri _root.scss
dosiye yacu.
Ingero
Impinduka za CSS zitanga ihinduka risa nimpinduka za Sass, ariko bidakenewe gukusanya mbere yo guhabwa mushakisha. Kurugero, hano turimo dusubiramo imyandikire yurupapuro rwacu hamwe nuburyo bwo guhuza hamwe na CSS ihinduka.
Ibihinduka
Mugihe twabanje gushyiramo ibice byahinduwe muri CSS yacu (urugero, --breakpoint-md
), ibyo ntibishyigikiwe mubibazo byitangazamakuru , ariko birashobora gukoreshwa mumategeko mubibazo byitangazamakuru. Izi mpinduka zinyuranye ziguma muri CSS yakozwe kugirango ihuze inyuma bitewe nuko ishobora gukoreshwa na JavaScript. Wige byinshi muri sp .
Dore urugero rwibidashyigikiwe:
Kandi dore urugero rwibyashyigikiwe: