You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Adds new functions to generate additional Sass maps
- Adds new root variables for rgb() versions of our theme colors, plus a few extras
- Adds ability to change the alpha transparency of text color and background color utilities with new utilities, inline styles, or local CSS var
- Updates documentation for color and background-color utilities pages
- Deprecates .text-black-50 and .text-white-50 since those (and additional transparency levels) can be generated on the fly
Change approach slightly to prevent cascade
Copy file name to clipboardExpand all lines: site/content/docs/5.0/utilities/background.md
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,44 @@ Do you need a gradient in your custom CSS? Just add `background-image: var(--bs-
35
35
{{< /colors.inline >}}
36
36
{{< /markdown >}}
37
37
38
+
## Opacity
39
+
40
+
<smallclass="d-inline-flex px-2 py-1 font-monospace text-muted border rounded-3">Added in v5.1.0</small>
41
+
42
+
As of v5.1.0, `background-color` utilities are generated with Sass using CSS variables. This allows for real-time color changes without compilation and dynamic alpha transparency changes.
We use an RGB version of our `--bs-succes` (with the value of `25, 135, 84`) CSS variable and attached a second CSS variable, `--bs-bg-opacity`, for the alpha transparency (with no default value, but a fallback of `1`). That means anytime you use `.bg-success` now, your computed `color` value is `rgba(25, 135, 84, 1)`.
56
+
57
+
### Example
58
+
59
+
To change that opacity, override `--bs-bg-opacity` via custom styles or inline styles.
60
+
61
+
{{< example >}}
62
+
<divclass="bg-success p-2 text-white">This is default success background</div>
63
+
<divclass="bg-success p-2"style="--bs-bg-opacity: .5;">This is 50% opacity success background</div>
64
+
{{< /example >}}
65
+
66
+
Or, choose from any of the `.bg-opacity` utilities:
67
+
68
+
{{< example >}}
69
+
<divclass="bg-success p-2 text-white">This is default success background</div>
70
+
<divclass="bg-success p-2 text-white bg-opacity-75">This is 75% opacity success background</div>
71
+
<divclass="bg-success p-2 text-dark bg-opacity-50">This is 50% opacity success background</div>
72
+
<divclass="bg-success p-2 text-dark bg-opacity-25">This is 25% opacity success background</div>
73
+
<divclass="bg-success p-2 text-dark bg-opacity-10">This is 10% opacity success background</div>
74
+
{{< /example >}}
75
+
38
76
## Sass
39
77
40
78
In addition to the following Sass functionality, consider reading about our included [CSS custom properties]({{< docsref "/customize/css-variables" >}}) (aka CSS variables) for colors and more.
@@ -63,6 +101,14 @@ Grayscale colors are also available as a Sass map. **This map is not used to gen
**No mixins are used to generate our background utilities**, but we do have some additional mixins for other situations where you'd like to create your own gradients.
**Deprecation:** With the addition of `.text-opacity-*` utilities and CSS variables for text utilities, `.text-black-50` and `.text-white-50` are deprecated as of v5.1.0. They'll be removed in v6.0.0.
<smallclass="d-inline-flex px-2 py-1 font-monospace text-muted border rounded-3">Added in v5.1.0</small>
37
+
38
+
As of v5.1.0, text color utilities are generated with Sass using CSS variables. This allows for real-time color changes without compilation and dynamic alpha transparency changes.
We use an RGB version of our `--bs-primary` (with the value of `13, 110, 253`) CSS variable and attached a second CSS variable, `--bs-text-opacity`, for the alpha transparency (with no default value, but a fallback of `1`). That means anytime you use `.text-primary` now, your computed `color` value is `rgba(13, 110, 253, 1)`.
52
+
53
+
### Example
54
+
55
+
To change that opacity, override `--bs-text-opacity` via custom styles or inline styles.
56
+
57
+
{{< example >}}
58
+
<divclass="text-primary">This is default primary text</div>
59
+
<divclass="text-primary"style="--bs-text-opacity: .5;">This is 50% opacity primary text</div>
60
+
{{< /example >}}
61
+
62
+
Or, choose from any of the `.text-opacity` utilities:
63
+
64
+
{{< example >}}
65
+
<divclass="text-primary">This is default primary text</div>
66
+
<divclass="text-primary text-opacity-75">This is 75% opacity primary text</div>
67
+
<divclass="text-primary text-opacity-50">This is 50% opacity primary text</div>
68
+
<divclass="text-primary text-opacity-25">This is 25% opacity primary text</div>
69
+
{{< /example >}}
70
+
30
71
## Specificity
31
72
32
73
Sometimes contextual classes cannot be applied due to the specificity of another selector. In some cases, a sufficient workaround is to wrap your element's content in a `<div>` or more semantic element with the desired class.
@@ -57,6 +98,14 @@ Grayscale colors are also available as a Sass map. **This map is not used to gen
Color utilities are declared in our utilities API in `scss/_utilities.scss`. [Learn how to use the utilities API.]({{< docsref "/utilities/api#using-the-api" >}})
0 commit comments