mirror of
https://github.com/twbs/bootstrap.git
synced 2024-11-30 12:24:19 +01:00
41 lines
1.3 KiB
Markdown
41 lines
1.3 KiB
Markdown
|
---
|
||
|
layout: docs
|
||
|
title: CSS variables
|
||
|
description: Use Bootstrap's CSS custom properties for fast and forward-looking design and development.
|
||
|
group: customize
|
||
|
toc: true
|
||
|
---
|
||
|
|
||
|
Bootstrap includes around two dozen [CSS custom properties (variables)](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) in its compiled CSS. 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.
|
||
|
|
||
|
## Available variables
|
||
|
|
||
|
Here are the variables we include (note that the `:root` is required). They're located in our `_root.scss` file.
|
||
|
|
||
|
{{< highlight css >}}
|
||
|
{{< root.inline >}}
|
||
|
{{- $css := readFile "dist/css/bootstrap.css" -}}
|
||
|
{{- $match := findRE ":root {([^}]*)}" $css 1 -}}
|
||
|
|
||
|
{{- if (eq (len $match) 0) -}}
|
||
|
{{- errorf "Got no matches for :root in %q!" $.Page.Path -}}
|
||
|
{{- end -}}
|
||
|
|
||
|
{{- index $match 0 -}}
|
||
|
|
||
|
{{< /root.inline >}}
|
||
|
{{< /highlight >}}
|
||
|
|
||
|
## 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.
|
||
|
|
||
|
{{< highlight css >}}
|
||
|
body {
|
||
|
font: 1rem/1.5 var(--font-family-sans-serif);
|
||
|
}
|
||
|
a {
|
||
|
color: var(--blue);
|
||
|
}
|
||
|
{{< /highlight >}}
|