Theming Bootstrap
Sinthani Mwamakonda Anu Bootstrap 4 ndi zosintha zathu zatsopano za Sass pazokonda zapadziko lonse lapansi kuti mukhale ndi mitu yosavuta komanso kusintha magawo.
Mawu Oyamba
Mu Bootstrap 3, mitu idayendetsedwa makamaka ndi kupitilira mu LESS, CSS yodziwika bwino, ndi pepala lamutu losiyana lomwe tidaphatikiza dist
m'mafayilo athu. Ndi khama, wina atha kukonzanso mawonekedwe a Bootstrap 3 osakhudza mafayilo oyambira. Bootstrap 4 imapereka njira yodziwika bwino, koma yosiyana pang'ono.
Tsopano, mitu imakwaniritsidwa ndi mitundu ya Sass, mamapu a Sass, ndi CSS yokhazikika. Palibenso pepala lodzipatulira lamutu; m'malo mwake, mutha kuloleza mutu womwe wamangidwa kuti uwonjezere ma gradients, mithunzi, ndi zina zambiri.
Sass
Gwiritsani ntchito mafayilo athu a Sass kuti mutengere mwayi pazosintha, mamapu, zosakaniza, ndi zina zambiri. Pakumanga kwathu tawonjezera kulondola kwa Sass kufika pa 6 (mwachisawawa ndi 5) kuti tipewe zovuta zozungulira msakatuli.
Mapangidwe a fayilo
Ngati n'kotheka, pewani kusintha mafayilo amtundu wa Bootstrap. Kwa Sass, izi zikutanthauza kupanga zolemba zanu zomwe zimalowetsa Bootstrap kuti mutha kusintha ndikuwonjezera. Pongoganiza kuti mukugwiritsa ntchito phukusi loyang'anira ngati npm, mudzakhala ndi fayilo yomwe imawoneka motere:
Ngati mwatsitsa mafayilo athu oyambira ndipo simukugwiritsa ntchito woyang'anira phukusi, mudzafuna kukhazikitsa pamanja china chofanana ndi mawonekedwewo, kusunga mafayilo amtundu wa Bootstrap kukhala osiyana ndi anu.
Kuitanitsa
M'mafayilo anu custom.scss
, mudzalowetsa mafayilo a Sass a Bootstrap. Muli ndi njira ziwiri: kuphatikiza zonse za Bootstrap, kapena sankhani magawo omwe mukufuna. Timalimbikitsa omalizawa, ngakhale dziwani kuti pali zofunika zina ndi zodalira pazigawo zathu zonse. Muyeneranso kuphatikiza JavaScript yamapulagini athu.
Ndi kukhazikitsa komweko, mutha kuyamba kusintha zosintha zilizonse za Sass ndi mamapu anu custom.scss
. Mutha kuyambanso kuwonjezera magawo a Bootstrap pansi // Optional
pagawo ngati pakufunika. Tikukulangizani kuti mugwiritse ntchito stack yonse kuchokera mufayilo yathu bootstrap.scss
ngati poyambira.
Zosintha zosinthika
Kusintha kulikonse kwa Sass mu Bootstrap 4 kumaphatikizapo !default
mbendera yomwe imakupatsani mwayi wopitilira mtengo wosasinthika mu Sass yanu popanda kusintha magwero a Bootstrap. Koperani ndi kumata zosintha momwe zingafunikire, sinthani zikhalidwe zawo, ndikuchotsa !default
mbendera. Ngati kusintha kwaperekedwa kale, ndiye kuti sikugawidwenso ndi zokhazikika mu Bootstrap.
Mupeza mndandanda wathunthu wazosintha za Bootstrap mu scss/_variables.scss
. Zosintha zina zimayikidwa ku null
, zosinthazi sizitulutsa katundu pokhapokha zitatsitsidwa pamasinthidwe anu.
Zosintha zosinthika mkati mwa fayilo yomweyo ya Sass zitha kubwera zisanachitike kapena zitatha zosinthika. Komabe, mukamawonjezera mafayilo a Sass, zowonjezera zanu ziyenera kubwera musanalowetse mafayilo a Sass a Bootstrap.
Nachi chitsanzo chomwe chimasintha ndikulowetsa background-color
ndikulowetsa Bootstrap kudzera npm:color
<body>
Bwerezani ngati kuli kofunikira pakusintha kulikonse mu Bootstrap, kuphatikiza zosankha zapadziko lonse lapansi pansipa.
Mapu ndi malupu
Bootstrap 4 imaphatikizapo mamapu ochepa a Sass, awiriawiri ofunika kwambiri omwe amapangitsa kuti zikhale zosavuta kupanga mabanja a CSS yogwirizana. Timagwiritsa ntchito mamapu a Sass pamitundu yathu, mapulaneti a gridi, ndi zina zambiri. Monga zosinthika za Sass, mamapu onse a Sass amaphatikiza !default
mbendera ndipo amatha kuchotsedwa ndikukulitsidwa.
Ena mwa mamapu athu a Sass amaphatikizidwa kukhala opanda kanthu mwachisawawa. Izi zimachitika kuti zilole kukulitsa kosavuta kwa mapu a Sass, koma zimabwera pamtengo wopangitsa kuchotsa zinthu pamapu kukhala kovuta kwambiri.
Sinthani mapu
Kuti musinthe mtundu womwe ulipo $theme-colors
pamapu athu, onjezani zotsatirazi pafayilo yanu yamtundu wa Sass:
Onjezani ku mapu
Kuti muwonjezere mtundu watsopano ku $theme-colors
, onjezani kiyi yatsopano ndi mtengo:
Chotsani pamapu
Kuti muchotse mitundu pa $theme-colors
, kapena mapu ena aliwonse, gwiritsani ntchito map-remove
. Dziwani kuti muyenera kuyiyika pakati pa zomwe tikufuna ndi zomwe mungasankhe:
Makiyi ofunikira
Bootstrap imatengera kukhalapo kwa makiyi ena mkati mwa mamapu a Sass momwe timagwiritsira ntchito ndikuwonjezera tokha. Mukamasintha mamapu omwe akuphatikizidwa, mutha kukumana ndi zolakwika pomwe kiyi ya mapu a Sass ikugwiritsidwa ntchito.
Mwachitsanzo, timagwiritsa ntchito primary
, success
, ndi danger
makiyi ochokera $theme-colors
ku maulalo, mabatani, ndi mawonekedwe a fomu. Kusintha makiyi a makiyiwa sikuyenera kubweretsa zovuta, koma kuwachotsa kungayambitse zovuta za Sass. Muzochitika izi, muyenera kusintha nambala ya Sass yomwe imagwiritsa ntchito mfundozo.
Ntchito
Bootstrap imagwiritsa ntchito ntchito zingapo za Sass, koma kagawo kakang'ono kokha kamene kamagwira ntchito pamutu wamba. Taphatikiza ntchito zitatu zopezera makonda kuchokera pamapu amitundu:
Izi zimakupatsani mwayi wosankha mtundu umodzi pamapu a Sass monga momwe mungagwiritsire ntchito mtundu wa v3.
Tilinso ndi ntchito ina yopezera mulingo winawake wamtundu pamapu$theme-colors
. Miyezo yolakwika idzachepetsa mtunduwo, pomwe milingo yayikulu idzadetsedwa.
Pochita, mumatcha ntchitoyi ndikudutsa magawo awiri: dzina la mtundu kuchokera $theme-colors
(mwachitsanzo, choyambirira kapena chowopsa) ndi kuchuluka kwa manambala.
Ntchito zowonjezera zitha kuwonjezedwa mtsogolomo kapena makonda anu a Sass kuti mupange magwiridwe antchito a mamapu owonjezera a Sass, kapenanso yachidule ngati mukufuna kukhala olankhula kwambiri.
Kusiyana kwamitundu
Ntchito yowonjezera yomwe timaphatikizapo mu Bootstrap ndi ntchito yosiyanitsa mitundu, color-yiq
. Imagwiritsa ntchito malo amtundu wa YIQ kuti ibweretse kuwala ( #fff
) kapena mdima ( #111
) wosiyana wa mtundu kutengera mtundu womwe watchulidwa. Izi ndizothandiza makamaka pazosakaniza kapena malupu pomwe mukupanga makalasi angapo.
Mwachitsanzo, kupanga zosintha zamitundu $theme-colors
pamapu athu:
Itha kugwiritsidwanso ntchito pazosowa zosiyanitsa kamodzi:
Mutha kutchulanso mtundu woyambira ndi mapu athu amitundu:
Kuthawa SVG
Timagwiritsa ntchito escape-svg
ntchitoyi kuthawa <
, >
ndi #
zilembo zazithunzi zakumbuyo za SVG. Zilembozi ziyenera kuthawa kuti ziperekedwe bwino zithunzi zakumbuyo mu IE.
Onjezani ndi Kuchotsa ntchito
Timagwiritsa ntchito add
ndi subtract
ntchito kukulunga ntchito ya CSS calc
. Cholinga chachikulu cha ntchitoyi ndikupewa zolakwika pamene mtengo wa "unitless" uperekedwa 0
m'mawu calc
. Mawu ngati calc(10px - 0)
angabweretse cholakwika mu asakatuli onse, ngakhale ali olondola masamu.
Chitsanzo pomwe calc ili yoyenera:
Chitsanzo pomwe calc ndi yolakwika:
Zosankha za Sass
Sinthani Mwamakonda Anu Bootstrap 4 ndi fayilo yathu yosinthira makonda opangidwa ndikusintha mosavuta zokonda zapadziko lonse za CSS ndi $enable-*
mitundu yatsopano ya Sass. Chotsani mtengo wosinthika ndikuwonjezeranso npm run test
ngati pakufunika.
Mutha kupeza ndikusintha masinthidwe awa pazosankha zazikulu zapadziko lonse lapansi mufayilo ya Bootstrap scss/_variables.scss
.
Zosintha | Makhalidwe | Kufotokozera |
---|---|---|
$spacer |
1rem (zosakhazikika), kapena mtengo uliwonse> 0 |
Imatchula mtengo wokhazikika wa spacer kuti apange zida zathu za spacer . |
$enable-rounded |
true (zosakhazikika) kapenafalse |
Imathandizira border-radius masitayelo ofotokozedweratu pazinthu zosiyanasiyana. |
$enable-shadows |
true kapena false (zosakhazikika) |
Imathandizira box-shadow masitayelo ofotokozedweratu pazinthu zosiyanasiyana. |
$enable-gradients |
true kapena false (zosakhazikika) |
Imathandizira ma gradients ofotokozedwatu kudzera background-image masitayelo pazinthu zosiyanasiyana. |
$enable-transitions |
true (zosakhazikika) kapenafalse |
Imathandiza predefined transition s pa zigawo zosiyanasiyana. |
$enable-prefers-reduced-motion-media-query |
true (zosakhazikika) kapenafalse |
Imayatsa prefers-reduced-motion funso pa media , zomwe zimapondereza makanema ojambula / zosinthika kutengera zomwe amakonda msakatuli / makina ogwiritsira ntchito. |
$enable-hover-media-query |
true kapena false (zosakhazikika) |
Yasiyidwa |
$enable-grid-classes |
true (zosakhazikika) kapenafalse |
Imathandizira kupanga makalasi a CSS pagululi (monga, .container , .row , .col-md-1 , etc.). |
$enable-caret |
true (zosakhazikika) kapenafalse |
Imayatsa pseudo element caret pa .dropdown-toggle . |
$enable-pointer-cursor-for-buttons |
true (zosakhazikika) kapenafalse |
Onjezani cholozera cha "dzanja" kuzinthu za batani zosalemala. |
$enable-print-styles |
true (zosakhazikika) kapenafalse |
Imayatsa masitaelo kuti muwongolere kusindikiza. |
$enable-responsive-font-sizes |
true kapena false (zosakhazikika) |
Imayatsa kukula kwa mafonti kuyankha . |
$enable-validation-icons |
true (zosakhazikika) kapenafalse |
Imayatsa background-image zithunzi mkati mwazolemba ndi mafomu ena ovomerezeka kuti atsimikizire. |
$enable-deprecation-messages |
true kapena false (zosakhazikika) |
Khazikitsani kuti true muwonetse machenjezo mukamagwiritsa ntchito zosakaniza zomwe zatsitsidwa ndi ntchito zomwe zakonzedwa kuti zichotsedwe mu v5 . |
Mtundu
Zambiri mwazinthu zosiyanasiyana za Bootstrap ndi zofunikira zimamangidwa kudzera mumitundu ingapo yofotokozedwa pamapu a Sass. Mapuwa atha kutsatidwa ku Sass kuti apange malamulo angapo.
Mitundu yonse
Mitundu yonse yomwe ilipo mu Bootstrap 4, imapezeka ngati mitundu ya Sass ndi mapu a Sass mufayilo scss/_variables.scss
. Izi zidzawonjezedwa m'mabuku ang'onoang'ono otsatirawa kuti muwonjezere mithunzi yowonjezera, mofanana ndi palette ya grayscale yomwe timaphatikizapo kale.
Umu ndi momwe mungagwiritsire ntchito izi mu Sass yanu:
Makalasi opangira utoto amapezekanso kuti akhazikike color
ndi background-color
.
M'tsogolomu, tikhala ndi cholinga chopereka mamapu a Sass ndi zosintha zamitundu yamtundu uliwonse monga momwe tachitira ndi mitundu yotuwa pansipa.
Mitundu yamutu
Timagwiritsa ntchito kagawo kakang'ono kamitundu yonse kuti tipange utoto wocheperako popanga masikimu amitundu, omwe amapezekanso ngati mitundu ya Sass ndi mapu a Sass mufayilo ya Bootstrap scss/_variables.scss
.
Imvi
Mitundu yokulirapo yamitundu yotuwa ndi mapu a Sass scss/_variables.scss
amithunzi yotuwa mosasinthasintha pulojekiti yanu. Zindikirani kuti awa ndi "imvi yoziziritsa", yomwe imakonda kumveka bwino kwa buluu, m'malo mwa imvi yopanda ndale.
Mkati scss/_variables.scss
, mupeza mitundu yamitundu ya Bootstrap ndi mapu a Sass. Nachi chitsanzo cha $colors
mapu a Sass:
Onjezani, chotsani, kapena sinthani zinthu zomwe zili pamapu kuti zisinthe momwe zimagwiritsidwira ntchito m'zigawo zina zambiri. Tsoka ilo panthawiyi, sizinthu zonse zomwe zimagwiritsa ntchito mapu a Sass. Zosintha zamtsogolo zidzayesetsa kukonza izi. Mpaka pamenepo, konzekerani kugwiritsa ntchito ${color}
zosinthika ndi mapu a Sass awa.
Zigawo
Zambiri mwazinthu ndi zofunikira za Bootstrap zimamangidwa ndi @each
malupu omwe amayenda pamapu a Sass. Izi ndizothandiza kwambiri popanga mitundu yosiyanasiyana mwazinthu zathu $theme-colors
ndikupanga mitundu yomvera pagawo lililonse. Mukakonza mamapu awa a Sass ndikuphatikizanso, mudzawona zosintha zanu zikuwonekera mu malupu awa.
Zosintha
Zambiri mwazinthu za Bootstrap zimamangidwa ndi njira yosinthira kalasi yoyambira. Izi zikutanthauza kuti kuchuluka kwa makongoletsedwe kuli m'gulu loyambira (mwachitsanzo, .btn
) pomwe masitayelo amangochitika m'makalasi osintha (mwachitsanzo, .btn-danger
). Makalasi osinthira awa amapangidwa kuchokera $theme-colors
pamapu kuti asinthe makonda a nambala ndi dzina la makalasi athu osintha.
Nazi zitsanzo ziwiri za momwe timadumphira $theme-colors
pamapu kuti tipange zosintha pagawo ndi .alert
zida zathu zonse .bg-*
zakumbuyo.
Womvera
Malupu a Sass awa samangokhala mamapu amitundu, mwina. Mukhozanso kupanga mitundu yosiyanasiyana yamagawo anu kapena zofunikira. Tengani mwachitsanzo zida zathu zoyankhulirana ndi mawu pomwe timasakaniza @each
kuzungulira kwa $grid-breakpoints
mapu a Sass ndi funso latolankhani.
Ngati mukufunika kusintha $grid-breakpoints
, zosintha zanu zidzagwira ntchito pamalupu onse omwe akupitilira pamapuwo.
Zosintha za CSS
Bootstrap 4 imaphatikizapo pafupifupi magawo awiri a CSS makonda (zosinthika) mu CSS yake yopangidwa. Izi zimapereka mwayi wosavuta kuzinthu zomwe zimagwiritsidwa ntchito nthawi zambiri monga mitundu yathu yamutu, zodulira, ndi milu ya zilembo zoyambirira mukamagwira ntchito mu Inspector ya msakatuli wanu, bokosi la sandbox, kapena ma prototyping wamba.
Zosintha zomwe zilipo
Nazi zosintha zomwe timaphatikiza (zindikirani kuti :root
ndizofunikira). Zili mufayilo yathu _root.scss
.
Zitsanzo
Zosintha za CSS zimapereka kusinthasintha kofanana ndi zosintha za Sass, koma popanda kufunika kophatikiza musanatumizidwe kwa osatsegula. Mwachitsanzo, apa tikukhazikitsanso mafonti atsamba lathu ndi masitayelo olumikizirana ndi CSS.
Zosintha za Breakpoint
Ngakhale tidaphatikizirapo zosokoneza muzosintha zathu za CSS (mwachitsanzo, --breakpoint-md
), izi sizimathandizidwa pamafunso atolankhani , koma zitha kugwiritsidwabe ntchito mkati mwamalamulo pamafunso azama TV. Zosintha za breakpoint izi zimakhalabe mu CSS yopangidwa kuti zigwirizane ndi kumbuyo chifukwa zitha kugwiritsidwa ntchito ndi JavaScript. Dziwani zambiri mu spec .
Nachi chitsanzo cha zomwe sizikuthandizidwa:
Ndipo nachi chitsanzo cha zomwe zimathandizidwa: