CSS variables
Siv Bootstrap's CSS cov cuab yeej kev cai rau kev tsim thiab kev loj hlob sai thiab zoo.
Bootstrap suav nrog ntau CSS kev cai khoom (kuj hloov pauv) hauv nws cov CSS suav nrog rau kev hloov kho lub sijhawm tiag tiag yam tsis tas yuav rov ua dua Sass. Cov no muab kev nkag tau yooj yim rau cov txiaj ntsig zoo ib yam li peb cov ntsiab lus xim, cov ntsiab lus tawg, thiab cov font loj loj thaum ua haujlwm hauv koj tus browser tus neeg soj ntsuam, code sandbox, lossis kev tsim qauv.
Tag nrho peb cov cuab yeej kev cai yog ua ntej nrogbs-
kom tsis txhob muaj teeb meem nrog CSS thib peb.
Root variables
Nov yog cov kev hloov pauv uas peb suav nrog (nco ntsoov tias qhov :root
yuav tsum tau ua) uas tuaj yeem nkag mus tau txhua qhov chaw Bootstrap's CSS tau thauj khoom. Lawv nyob hauv peb cov _root.scss
ntaub ntawv thiab suav nrog peb cov ntaub ntawv dist uas tau muab tso ua ke.
:root {
--bs-blue: #0d6efd;
--bs-indigo: #6610f2;
--bs-purple: #6f42c1;
--bs-pink: #d63384;
--bs-red: #dc3545;
--bs-orange: #fd7e14;
--bs-yellow: #ffc107;
--bs-green: #198754;
--bs-teal: #20c997;
--bs-cyan: #0dcaf0;
--bs-white: #fff;
--bs-gray: #6c757d;
--bs-gray-dark: #343a40;
--bs-gray-100: #f8f9fa;
--bs-gray-200: #e9ecef;
--bs-gray-300: #dee2e6;
--bs-gray-400: #ced4da;
--bs-gray-500: #adb5bd;
--bs-gray-600: #6c757d;
--bs-gray-700: #495057;
--bs-gray-800: #343a40;
--bs-gray-900: #212529;
--bs-primary: #0d6efd;
--bs-secondary: #6c757d;
--bs-success: #198754;
--bs-info: #0dcaf0;
--bs-warning: #ffc107;
--bs-danger: #dc3545;
--bs-light: #f8f9fa;
--bs-dark: #212529;
--bs-primary-rgb: 13, 110, 253;
--bs-secondary-rgb: 108, 117, 125;
--bs-success-rgb: 25, 135, 84;
--bs-info-rgb: 13, 202, 240;
--bs-warning-rgb: 255, 193, 7;
--bs-danger-rgb: 220, 53, 69;
--bs-light-rgb: 248, 249, 250;
--bs-dark-rgb: 33, 37, 41;
--bs-white-rgb: 255, 255, 255;
--bs-black-rgb: 0, 0, 0;
--bs-body-color-rgb: 33, 37, 41;
--bs-body-bg-rgb: 255, 255, 255;
--bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
--bs-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
--bs-gradient: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
--bs-body-font-family: var(--bs-font-sans-serif);
--bs-body-font-size: 1rem;
--bs-body-font-weight: 400;
--bs-body-line-height: 1.5;
--bs-body-color: #212529;
--bs-body-bg: #fff;
}
Cov khoom sib txawv
Peb tseem tab tom pib siv cov cuab yeej kev cai raws li qhov sib txawv hauv zos rau ntau yam khoom. Txoj kev no peb tuaj yeem txo peb cov CSS sau ua ke, xyuas kom cov qauv tsis tau txais txiaj ntsig hauv qhov chaw xws li cov rooj sib ze, thiab tso cai rau qee qhov kev so yooj yim thiab txuas ntxiv ntawm Bootstrap Cheebtsam tom qab Sass muab tso ua ke.
Saib peb cov ntaub ntawv rooj rau qee qhov kev nkag siab txog qhov peb siv CSS hloov pauv li cas .
Peb kuj tseem siv CSS hloov pauv thoob plaws peb daim phiaj-tseem ceeb rau gutters-nrog rau kev siv cov khoom siv ntxiv los yav tom ntej.
Piv txwv
CSS variables muaj qhov hloov pauv zoo sib xws rau Sass's variables, tab sis tsis tas yuav tsum tau muab tso ua ke ua ntej muab rau browser. Piv txwv li, ntawm no peb tab tom rov pib dua peb nplooj ntawv font thiab txuas cov qauv nrog CSS sib txawv.
body {
font: 1rem/1.5 var(--bs-font-sans-serif);
}
a {
color: var(--bs-blue);
}
Daim phiaj tawg
Thaum peb suav nrog peb cov phiaj xwm phiaj xwm raws li CSS qhov sib txawv (tshwj tsis yog xs
), nco ntsoov tias CSS qhov sib txawv tsis ua haujlwm hauv cov lus nug xov xwm . Qhov no yog los ntawm kev tsim hauv CSS spec rau qhov sib txawv, tab sis tej zaum yuav hloov nyob rau hauv lub xyoo tom ntej nrog kev txhawb nqa rau env()
qhov sib txawv. Tshawb xyuas qhov no Stack Overflow teb rau qee qhov kev sib txuas pab tau. Lub sijhawm ntawd, koj tuaj yeem siv cov kev hloov pauv no hauv lwm qhov xwm txheej CSS, nrog rau hauv koj li JavaScript.