Bootstrap
Hindura Bootstrap 4 hamwe nuburyo bushya bwubatswe muri Sass ihindagurika kumiterere yisi yose ukunda kubintu byoroshye nibihinduka.
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.
Koresha isoko yacu Sass dosiye kugirango ukoreshe impinduka, ikarita, ivanga, nibindi byinshi.
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 kandi ukaba udakoresha pake yumuyobozi, uzakenera gushiraho intoki ikintu gisa nkiyo miterere, ukagumana dosiye yinkomoko ya Bootstrap itandukanye niyanyu.
Muriwe custom.scss
, uzatumiza inkomoko ya Bootstrap ya Sass dosiye. Ufite amahitamo abiri: shyiramo Bootstrap yose, cyangwa hitamo ibice ukeneye. Turashishikariza aba nyuma, nubwo menya 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 gukoresha ibicuruzwa byuzuye biva muri bootstrap.scss
dosiye yacu aho utangirira.
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 rwa Bootstrap ihinduka muri scss/_variables.scss
.
Ibihinduka birenze muri dosiye imwe ya Sass irashobora kuza mbere cyangwa nyuma yimiterere ihindagurika. Ariko, mugihe urenze hejuru ya 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.
Bootstrap 4 ikubiyemo amakarita ya Sass yintoki, ibyingenzi byingenzi byoroha kubyara imiryango ya CSS ifitanye isano. Dukoresha amakarita ya Sass kumabara yacu, grid yacitse, 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.
Guhindura ibara risanzwe kurikarita yacu $theme-colors
, ongeraho ibikurikira muri dosiye yawe ya Sass:
Kongera ibara rishya kuri $theme-colors
, ongeramo urufunguzo rushya nagaciro:
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:
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.
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.
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:
Hindura Bootstrap 4 hamwe na fayili yacu yubatswe yihariye kandi uhindure byoroshye CSS yisi yose hamwe nibintu bishya bya $enable-*
Sass. Kurenga agaciro k'ibihinduka hanyuma usubiremo npm run test
nkuko bikenewe.
Urashobora kubona no guhitamo ibyo bihinduka kubintu byingenzi byisi yose 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 utanga ibikoresho . |
$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-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. |
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 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.
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.
Ikirangantego cyagutse cyimyenda ihindagurika hamwe nikarita ya Sass muburyo scss/_variables.scss
bwigicucu kijimye cyumusatsi kumushinga wawe.
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 niyi karita ya Sass.
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.
Byinshi mubigize 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 abahindura .alert
ibice hamwe nibikorwa byacu byose byingenzi .bg-*
.
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.
Ukeneye guhindura ibyawe $grid-breakpoints
, impinduka zawe zizakoreshwa kumuzingo wose uzenguruka kuri iyo karita.
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.
Dore impinduka dushyiramo (menya ko :root
ibisabwa). Biri muri _root.scss
dosiye yacu.
Impinduka za CSS zitanga ihinduka risa nimpinduka za Sass, ariko bidakenewe gukusanya mbere yo guhabwa mushakisha. Kurugero, hano turimo gusubiramo imyandikire yurupapuro rwacu hamwe nuburyo bwo guhuza hamwe na CSS ihinduka.
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: