Theming Bootstrap a ni
Theming awlsam leh component thlak danglam theihna turin global style duhzawng atan kan built-in Sass variable thar hmangin Bootstrap 4 hi customize rawh.
Inhmelhriattirna
Bootstrap 3-ah chuan theming hi a tam zawk chu LESS-a variable override, custom CSS, leh kan dist
file-a kan dah tel theme stylesheet hran vang a ni. Eng emaw chen thawhrimna nen chuan Bootstrap 3 hmel chu core files te khawih lovin a redesign vek thei a ni. Bootstrap 4 hian hriat hlawh tak, mahse a danglam deuh deuh a pe a ni.
Tunah chuan theming hi Sass variables, Sass maps, leh custom CSS hmangin a tihlawhtling ta a ni. Theme stylesheet bik a awm tawh lo; chu ai chuan built-in theme hmangin gradient, shadow leh thil dang tam tak a dah theih nan i enable thei bawk.
Sass a ni
Kan source Sass file te hmang la, variable, map, mixin leh thil dang tam tak hmang tangkai rawh. Kan build ah hian browser rounding chungchanga harsatna awm lo turin Sass rounding precision chu 6 ah kan tisang a (by default ah 5 a ni).
File siam dan tur
A theih phawt chuan Bootstrap-a core files te chu siam danglam loh tur. Sass tan chuan Bootstrap import thei tur stylesheet siam la, chutiang chuan i siam danglam thei ang a, i extend thei ang. npm ang package manager i hmang ni ta se, hetiang hian file structure i nei ang:
Kan source files te i download tawh a, package manager i hmang lo a nih chuan chu structure ang chi chu manual-in i setup duh ang a, Bootstrap-a source files te chu i source files atang chuan a hranpaa dah ang che.
Import a ni
I custom.scss
, ah chuan Bootstrap source Sass files te chu i import ang. Thil pahnih i nei a: Bootstrap zawng zawng telh vek la, a nih loh leh i mamawh parts thlang rawh. Kan component hrang hrangah hian thil mamawh leh innghahna engemaw zat a awm tih hre reng mah ila, a hnuhnung zawk hi kan fuih a ni. Tin, kan plugins te tan JavaScript thenkhat i dah tel a ngai bawk ang.
Chu setup chu a awm tawh chuan i custom.scss
. // Optional
A tul angin section hnuaiah Bootstrap parts te pawh i dah tan thei bawk . Kan bootstrap.scss
file atanga import stack kimchang chu i tanna atan hmang turin kan rawt a che.
Variable a awm thei
Bootstrap 4 a Sass variable zawng zawngah hian !default
flag a awm vek a, chu chuan Bootstrap source code siam danglam ngai lovin i Sass-a variable default value chu override theihna a siamsak a ni. Variable te chu a tul angin copy leh paste la, an value te chu siam danglam la, !default
flag chu paih chhuak rawh. Variable pakhat chu assigned a nih tawh chuan Bootstrap-a default value-te hmangin a re-assign leh dawn lo.
Bootstrap-a variable list kimchang chu scss/_variables.scss
.
Sass file khat chhunga variable override te hi default variable hma emaw hnuah emaw a lo thleng thei a ni. Mahse, Sass file zawng zawng override i tih hian Bootstrap-a Sass file i import hmain i override te chu a lo thleng hmasa tur a ni.
Hetah hian npm hmanga Bootstrap import leh compile laiin background-color
and color
for the a thlak danglam thin entirnan kan rawn tarlang e :<body>
Bootstrap a variable eng pawh atan a tul angin repeat leh la, a hnuaia global option te pawh telh bawk ang che.
Map leh loop te
Bootstrap 4 hian Sass map tlemte a keng tel a, key value pairs hmangin CSS inzawm chhungkaw siam awlsam zawk a ni. Kan rawng hrang hrang, grid breakpoint leh thil dang dang atan Sass map kan hmang thin. Sass variable ang bawkin Sass map zawng zawngah hian !default
flag a awm vek a, overridden leh extend theih a ni.
Kan Sass map thenkhat chu default in empty ah an inzawm khawm thin. Hei hi Sass map pek tawh chu awlsam taka tihzauh theihna tura tih a ni a, mahse map atanga thil lakchhuah chu tlem a harsa zawka siamna tur senso a ni.
Map siam danglam rawh
Kan $theme-colors
map-a color awmsa siam danglam tur chuan i custom Sass file-ah a hnuaia mi hi dah la:
Map ah hian add rawh
-a rawng thar dah tur chuan $theme-colors
key leh value thar dah la:
Map atang hian paih chhuak rawh
$theme-colors
, emaw map dang emaw aṭanga rawng paih tûr chuan map-remove
. Kan mamawh leh duhthlan tur inkarah i dah tel tur a ni tih hre reng ang che:
Key mamawh a ni
Bootstrap hian Sass maps chhunga key bik thenkhat awm chu kan hman ang khan a pawm a, hengte hi keimahni ngeiin kan tizau a ni. Map telh te i customize lai hian Sass map key bik hmanna hmunah error i tawk thei ang.
Entirnan, link, button leh form state atan primary
, success
, leh danger
key from te kan hmang thin. $theme-colors
Heng key te value thlak hian harsatna a thlen tur a ni lo a, mahse paih chhuah hian Sass compilation chungchangah harsatna a thlen thei a ni. Heng instance-ah hian chutiang value hmangtu Sass code chu i siam danglam a ngai ang.
Hnathawh dan tur
Bootstrap hian Sass function engemaw zat a hmang a, mahse general theming atan chuan subset pakhat chauh hman theih a ni. Color map atanga value hmuh theihna tur function pathum kan dah tel a:
Hengte hian Sass map atanga color pakhat thlan theihna a siamsak a, chu chu v3 atanga color variable i hman dan ang chiah kha a ni.
Map atanga color level bik hmuh theihna tur function dang kan nei bawk . $theme-colors
Negative level value chuan a rawng a ti eng ang a, a sang zawk chuan a dum ang.
Practice-ah chuan function chu i ko ang a, parameter pahnih i pass ang: color from $theme-colors
(eg, primary emaw danger emaw) hming leh numeric level.
Nakin lawkah function dang emaw, Sass map dang atan level function siam turin i custom Sass emaw i dah belh thei ang a, verbose zawka awm duh chuan generic pawh i dah belh thei bawk ang.
Color hrang hrang a awm
Bootstrap-a kan dah belh function pakhat chu color contrast function, color-yiq
. YIQ color space hmangin base color tarlan a zirin light ( #fff
) emaw dark ( ) emaw contrast color chu automatic in a rawn pe kir leh thin. #111
He function hi mixin emaw loop emaw class tam tak i siamna hmunah a tangkai hle.
Entirnan, kan $theme-colors
map atanga color swatch siam tur chuan:
One-off contrast mamawhna atan pawh hman theih a ni:
Kan color map function hmangin base color pawh i tarlang thei bawk:
Sass duhthlan tur a awm
Kan built-in custom variables file hmangin Bootstrap 4 hi customize la, awlsam takin global CSS preferences chu $enable-*
Sass variable thar hmangin toggle thei ang che. Variable pakhat value chu override la, npm run test
a tul angin recompile rawh.
Bootstrap scss/_variables.scss
file ah hian key global option atan heng variable te hi i zawng thei a, i customize thei bawk.
A danglam thei | Hlutna hrang hrang | Hrilhfiahna |
---|---|---|
$spacer |
1rem (default), emaw value eng pawh > 0 |
Kan spacer utilities te programmatic taka siam chhuah theihna tur default spacer value a tarlang . |
$enable-rounded |
true (default) emaw a nifalse |
Component hrang hrangah predefined border-radius styles a siam thei. |
$enable-shadows |
true emaw false (default) emaw a ni. |
Component hrang hrangah predefined box-shadow styles a siam thei. |
$enable-gradients |
true emaw false (default) emaw a ni. |
background-image Component hrang hranga style hmanga predefined gradient te a tichak thei. |
$enable-transitions |
true (default) emaw a nifalse |
Component hrang hrangah predefined transition s a siam thei. |
$enable-prefers-reduced-motion-media-query |
true (default) emaw a nifalse |
Enables the prefers-reduced-motion media query , chu chuan a hmangtute browser/operating system duh dan a zirin animation/transition thenkhat a titawp thin. |
$enable-hover-media-query |
true emaw false (default) emaw a ni. |
A hman tawh loh |
$enable-grid-classes |
true (default) emaw a nifalse |
Grid system atana CSS class siam theihna a siam (eg, .container , .row , .col-md-1 , etc.). |
$enable-caret |
true (default) emaw a nifalse |
Pseudo element caret chu a enable a .dropdown-toggle ni. |
$enable-print-styles |
true (default) emaw a nifalse |
Printing tihchangtlunna tur style a siam thei. |
$enable-validation-icons |
true (default) emaw a nifalse |
background-image Textual inputs chhunga icon awmte leh validation state atan custom form thenkhat a enable thin. |
Rawng
Bootstrap-a component leh utility hrang hrang tam tak hi Sass map-a tarlan color hrang hrang hmanga siam a ni. He map hi Sass ah hian loop over theih a ni a, rang takin ruleset series siam theih a ni.
Color zawng zawng
Bootstrap 4-a color awm zawng zawng, Sass variable angin a awm a, scss/_variables.scss
file-ah Sass map a awm bawk. Hei hi a hnu lama minor release-ah te pawh shade dang dah belh turin tihzauh a ni ang a, grayscale palette kan dah tawh ang bawkin.
Hengte hi i Sass-a i hman theih dan tur chu hetiang hi a ni:
Color utility class pawh setting color
leh background-color
.
Nakin lawkah chuan a hnuaia grayscale color te kan tih ang khan Sass maps leh color hrang hrang shade te pek kan tum dawn a ni.
Theme rawng hrang hrang
Color zawng zawng subset hmangin color scheme siam nan color palette te zawk kan siam a, chu chu Sass variable angin a awm bawk a, Bootstraps scss/_variables.scss
file-ah Sass map pawh a awm bawk.
Grays te an ni
Gray variable set zau tak leh Sass map in scss/_variables.scss
hmangin i project pumpuiah gray shade inmil tak tak a awm thei. Hriat tur chu hengte hi “cool grays” an ni a, neutral grays aiin subtle blue tone lam an hawi zawk thin.
, chhungah hian scss/_variables.scss
Bootstrap-a color variable leh Sass map te i hmu ang. $colors
Sass map entir nan hetiang hian kan rawn tarlang e :
Map chhunga value te chu component dang tam takah hman dan update turin dah belh, paih emaw, siam danglam emaw. Vanduaithlak takin tun dinhmunah chuan component zawng zawng hian he Sass map hi an hmang vek lo. Nakin lawka update lo awm turte chuan hei hi tihchangtlun tumin hma an la ang. Chumi hma chuan ${color}
variable leh he Sass map hi hman dan tur ruahmanna siam rawh.
Component hrang hrangte
Bootstrap-a component leh utility tam tak hi @each
Sass map-a iterate thei loop hmanga siam a ni. Hei hi a bik takin kan component pakhat $theme-colors
variant siam nan leh breakpoint tin atan responsive variant siam nan a tangkai hle. Heng Sass maps te hi i customize a, recompile i tih hian i inthlak danglamna te chu heng loop ah te hian a lang chhuak nghal vek ang.
Modifier te pawh a awm
Bootstrap-a component tam tak hi base-modifier class approach hmanga siam a ni. Hei hian a awmzia chu styling bulk chu base class (eg, .btn
)-ah a awm a, style variation erawh chu modifier class (eg, .btn-danger
)-ah a innghat thung tihna a ni. Heng modifier class te hi $theme-colors
map atanga siam niin kan modifier class te number leh hming customizing siam a ni.
Hetah hian map leh kan background utility zawng zawnga $theme-colors
modifier kan siam theih nan map kan loop dan entirnan pahnih kan rawn tarlang e ..alert
.bg-*
Chhanna pe thei
Heng Sass loop te hi color maps chauh a ni lo, chutiang bawkin. I component emaw utilities emaw responsive variation i siam thei bawk. Entirnan kan responsive text alignment utilities te hi han la ila, chutah chuan Sass map @each
atana loop pakhat chu media query include nen kan mix a.$grid-breakpoints
I , i siam danglam a ngai a nih $grid-breakpoints
chuan, i tihdanglamte chu chu map chunga loop iterating zawng zawngah a hman vek ang.
CSS a danglamna tur a awm
Bootstrap 4 hian a compiled CSS ah hian CSS custom property (variables) dozen hnih vel a keng tel a. Hengte hian i browser-a Inspector, code sandbox, emaw general prototyping-a hnathawh hunah kan theme color, breakpoint, leh primary font stack ang chi value hman tlanglawn tak takte awlsam taka hmuh theihna a pe a ni.
Variable awm thei te
Hetah hian variable kan dah tel te chu (the :root
is required tih hre reng ang che). Kan _root.scss
file ah hian an awm a.
Entirna te
CSS variable te hian Sass-a variable te ang bawkin flexibility an pe a, mahse browser-a an rawn thawn hmain compilation a ngai lo. Entirnan, hetah hian kan page font leh link style te chu CSS variable hmangin kan reset a.
Breakpoint a danglamna te
A tir chuan kan CSS variable-ah breakpoint kan dah tel laiin (eg, --breakpoint-md
), hengte hi media query-ah chuan support a ni lo , mahse media query-ah chuan ruleset chhungah hman theih a la ni tho . Heng breakpoint variable te hi JavaScript hmanga hman theih an nih avangin backward compatibility atan compiled CSS ah an awm reng a ni. Spec ah hian zir belh rawh .
Hetah hian support lohte entir nan kan rawn tarlang e :
Tin, a thlawp dan entir nan hetiang hian kan rawn tarlang e :