CSS variables

CSS variables

Bootstrap includes around two dozen CSS custom properties (variables) in its compiled CSS, with dozens more on the way for improved customization on a per-component basis. These provide easy access to commonly used values like our theme colors, breakpoints, and primary font stacks when working in your browser’s inspector, a code sandbox, or general prototyping.

All our custom properties are prefixed with bs- to avoid conflicts with third party CSS.

Root variables

Here are the variables we include (note that the :root is required) that can be accessed anywhere Bootstrap’s CSS is loaded. They’re located in our _root.scss file and included in our compiled dist files.

: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-primary: #0d6efd;

--bs-secondary: #6c757d;

--bs-success: #198754;

--bs-info: #0dcaf0;

--bs-warning: #ffc107;

--bs-danger: #dc3545;

--bs-light: #f8f9fa;

--bs-dark: #212529;

--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));

}

Component variables

We’re also beginning to make use of custom properties as local variables for various components. This way we can reduce our compiled CSS, ensure styles aren’t inherited in places like nested tables, and allow some basic restyling and extending of Bootstrap components after Sass compilation.

Have a look at our table documentation for some insight into how we’re using CSS variables.

We’re also using CSS variables across our grids—primarily for gutters—with more component usage coming in the future.

Examples

CSS variables offer similar flexibility to Sass’s variables, but without the need for compilation before being served to the browser. For example, here we’re resetting our page’s font and link styles with CSS variables.

body {

font: 1rem/1.5 var(--bs-font-sans-serif);

}

a {

color: var(--bs-blue);

}

相关推荐

重庆地名里的“碚”“沱”都和它有关
求正规英国365网址

重庆地名里的“碚”“沱”都和它有关

📅 09-13 👁️ 8176
美女为何天天被分尸?伊藤润二的头牌《富江》
求正规英国365网址

美女为何天天被分尸?伊藤润二的头牌《富江》

📅 09-29 👁️ 3750
苹果5s16g扩64g内存(苹果手机16g能升级64G吗)
求正规英国365网址

苹果5s16g扩64g内存(苹果手机16g能升级64G吗)

📅 08-15 👁️ 8197
《NFO Viewer:轻松查看NFO文件的利器》
365彩票软件app下载

《NFO Viewer:轻松查看NFO文件的利器》

📅 09-30 👁️ 3691
世界杯2018赔率
求正规英国365网址

世界杯2018赔率

📅 09-02 👁️ 6613
巴西龟怎么看年龄是多少(如何鉴定龟的年龄?)
365彩票软件app下载

巴西龟怎么看年龄是多少(如何鉴定龟的年龄?)

📅 08-01 👁️ 2447