Sass
Shandisa yedu sosi mafaera eSass kutora mukana wekusiyana, mepu, musanganiswa, uye mabasa kukubatsira iwe kuvaka nekukurumidza uye kugadzirisa purojekiti yako.
Shandisa yedu sosi mafaera eSass kutora mukana wekusiyana, mepu, musanganiswa, nezvimwe.
Chimiro chefaira
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:
your-project/
├── scss
│ └── custom.scss
└── node_modules/
└── bootstrap
├── js
└── scss
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.
your-project/
├── scss
│ └── custom.scss
└── bootstrap/
├── js
└── scss
Importing
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.
// Custom.scss
// Option A: Include all of Bootstrap
// Include any default variable overrides here (though functions won't be available)
@import "../node_modules/bootstrap/scss/bootstrap";
// Then add additional custom code here
// Custom.scss
// Option B: Include parts of Bootstrap
// 1. Include functions first (so you can manipulate colors, SVGs, calc, etc)
@import "../node_modules/bootstrap/scss/functions";
// 2. Include any default variable overrides here
// 3. Include remainder of required Bootstrap stylesheets
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";
@import "../node_modules/bootstrap/scss/root";
// 4. Include any optional Bootstrap CSS as needed
@import "../node_modules/bootstrap/scss/utilities";
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
@import "../node_modules/bootstrap/scss/images";
@import "../node_modules/bootstrap/scss/containers";
@import "../node_modules/bootstrap/scss/grid";
@import "../node_modules/bootstrap/scss/helpers";
// 5. Optionally include utilities API last to generate classes based on the Sass map in `_utilities.scss`
@import "../node_modules/bootstrap/scss/utilities/api";
// 6. Add additional custom code here
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.
Variable defaults
Yese Sass inosiyana muBootstrap inosanganisira iyo !default
mureza inokubvumidza kuti uwedzere kukosha kwekusiyana kweiyo Sass 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.
Iwe uchawana iyo yakazara runyorwa rweBootstrap's akasiyana mu scss/_variables.scss
. Mamwe mavhezheni akaiswa ku null
, aya akasiyana haabudise chivakwa kunze kwekunge akadarika mukumisikidzwa kwako.
Kusiyana kwakasiyana kunofanirwa kuuya mushure mekunge mabasa edu atengeswa kunze kwenyika, asi zvisati zvasara zvekunze.
Heino muenzaniso unoshandura iyo background-color
uye color
yeiyo <body>
kana uchipinza uye kunyora Bootstrap kuburikidza npm:
// Required
@import "../node_modules/bootstrap/scss/functions";
// Default variable overrides
$body-bg: #000;
$body-color: #111;
// Required
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";
@import "../node_modules/bootstrap/scss/root";
// Optional Bootstrap components here
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
// etc
Dzokorora sezvinodiwa kune chero shanduko muBootstrap, kusanganisira sarudzo dzepasirese pazasi.
Mepu uye zvishwe
Bootstrap inosanganisira mashoma emamepu eSass, mapikicha akakosha 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.
Shandura mepu
Zvese zvakasiyana $theme-colors
pamepu zvinotsanangurwa sezvimiro zvakamira. Kuti ugadzirise ruvara rwuripo $theme-colors
pamepu yedu, wedzera zvinotevera kune yako tsika Sass faira:
$primary: #0074d9;
$danger: #ff4136;
Gare gare, aya akasiyana akaiswa muBootstrap's $theme-colors
mepu:
$theme-colors: (
"primary": $primary,
"danger": $danger
);
Wedzera kumepu
Wedzera mavara matsva ku $theme-colors
, kana chero imwe mepu, nekugadzira mepu itsva yeSass ine tsika dzako tsika uye kuisanganisa nemepu yekutanga. Pakadai, tichagadzira $custom-colors
mepu itsva toisanganisa ne $theme-colors
.
// Create your own map
$custom-colors: (
"custom-color": #900
);
// Merge the maps
$theme-colors: map-merge($theme-colors, $custom-colors);
Bvisa kubva pamepu
Kubvisa mavara kubva $theme-colors
, kana chero imwe mepu, shandisa map-remove
. Ziva kuti unofanirwa kuiisa pakati pezvatinoda uye sarudzo:
// Required
@import "../node_modules/bootstrap/scss/functions";
@import "../node_modules/bootstrap/scss/variables";
@import "../node_modules/bootstrap/scss/mixins";
@import "../node_modules/bootstrap/scss/root";
$theme-colors: map-remove($theme-colors, "info", "light", "dark");
// Optional
@import "../node_modules/bootstrap/scss/reboot";
@import "../node_modules/bootstrap/scss/type";
// etc
Makiyi anodiwa
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.
Mabasa
Colors
Padivi pemamepu eSass atinawo, mavara edingindira anogonawo kushandiswa seakamira akasarudzika, senge $primary
.
.custom-element {
color: $gray-100;
background-color: $dark;
}
Iwe unogona kujekesa kana kusviba mavara neBootstrap tint-color()
uye shade-color()
mabasa. Aya mabasa achasanganisa mavara neatema kana chena, kusiyana nekwaSass 'yekuzvarwa lighten()
uye darken()
mabasa ayo anozoshandura kureruka nehuwandu hwakatarwa, izvo kazhinji hazvitungamiri kune inodiwa mhedzisiro.
// Tint a color: mix a color with white
@function tint-color($color, $weight) {
@return mix(white, $color, $weight);
}
// Shade a color: mix a color with black
@function shade-color($color, $weight) {
@return mix(black, $color, $weight);
}
// Shade the color if the weight is positive, else tint it
@function shift-color($color, $weight) {
@return if($weight > 0, shade-color($color, $weight), tint-color($color, -$weight));
}
Mukuita, iwe waizodaidza basa racho uye wopfuudza muvara uye uremu paramita.
.custom-element {
color: tint-color($primary, 10%);
}
.custom-element-2 {
color: shade-color($danger, 30%);
}
Kusiyana kwemavara
Kuti isangane nemiyero yeWCAG 2.0 yekusvikika yekusiyana kwemavara , vanyori vanofanirwa kupa muyero wemusiyano weinenge 4.5:1 , kunze kwemashoma.
Rimwe basa ratinosanganisa muBootstrap ndiro basa rekusiyanisa ruvara, color-contrast
. Inoshandisa iyo WCAG 2.0 algorithm pakuverenga mitsara yekusiyanisa zvichienderana nechiedza chepakati munzvimbo sRGB
yeruvara kuti idzorere otomatiki mwenje ( #fff
), dema ( #212529
) kana dema ( #000
) mutsauko 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:
@each $color, $value in $theme-colors {
.swatch-#{$color} {
color: color-contrast($value);
}
}
Inogona zvakare kushandiswa kune imwe-off mutsauko zvinodiwa:
.custom-element {
color: color-contrast(#000); // returns `color: #fff`
}
Iwe unogona zvakare kutsanangura ruvara rwepasi nemepu yedu yemavara mabasa:
.custom-element {
color: color-contrast($dark); // returns `color: #fff`
}
Escape SVG
Isu tinoshandisa escape-svg
basa kutiza iyo <
, >
uye #
mavara eSVG kumashure mifananidzo. Paunenge uchishandisa escape-svg
basa, data URIs inofanirwa kutorwa.
Wedzera uye Bvisa mabasa
Isu tinoshandisa iyo add
uye subtract
mabasa kuputira iyo CSS calc
basa. Chinangwa chikuru chemabasa aya ndechekudzivirira kukanganisa kana 0
kukosha kwe "unitless" kuchipfuudzwa muchirevo calc
. Matauriro akadai calc(10px - 0)
anodzosa chikanganiso mumabhurawuza ese, kunyangwe ari masvomhu chaiwo.
Muenzaniso apo calc inoshanda:
$border-radius: .25rem;
$border-width: 1px;
.element {
// Output calc(.25rem - 1px) is valid
border-radius: calc($border-radius - $border-width);
}
.element {
// Output the same calc(.25rem - 1px) as above
border-radius: subtract($border-radius, $border-width);
}
Muenzaniso apo calc isiri kushanda:
$border-radius: .25rem;
$border-width: 0;
.element {
// Output calc(.25rem - 0) is invalid
border-radius: calc($border-radius - $border-width);
}
.element {
// Output .25rem
border-radius: subtract($border-radius, $border-width);
}
Mixins
Dhairekitori redu scss/mixins/
rine matani emusanganiswa ayo ane simba zvikamu zveBootstrap uye anogona zvakare kushandiswa pane yako wega purojekiti.
Zvirongwa zvemavara
Shorthand mixin prefers-color-scheme
yemubvunzo wenhau inowanikwa nerutsigiro rwe light
,, dark
uye tsika yemavara zvirongwa.
@mixin color-scheme($name) {
@media (prefers-color-scheme: #{$name}) {
@content;
}
}
.custom-element {
@include color-scheme(dark) {
// Insert dark mode styles here
}
@include color-scheme(custom-named-scheme) {
// Insert custom color scheme styles here
}
}