diff --git a/scss/_helpers.scss b/scss/_helpers.scss index 4a989f5a5..644b693fb 100644 --- a/scss/_helpers.scss +++ b/scss/_helpers.scss @@ -1,4 +1,5 @@ @import "helpers/clearfix"; +@import "helpers/color-bg"; @import "helpers/colored-links"; @import "helpers/ratio"; @import "helpers/position"; diff --git a/scss/helpers/_color-bg.scss b/scss/helpers/_color-bg.scss new file mode 100644 index 000000000..c1e7dc5b7 --- /dev/null +++ b/scss/helpers/_color-bg.scss @@ -0,0 +1,7 @@ +@each $color, $value in $theme-colors { + $color-rgb: to-rgb($value); + .text-bg-#{$color} { + color: color-contrast($value) !important; // stylelint-disable-line declaration-no-important + background-color: rgba($color-rgb, var(--#{$prefix}bg-opacity, 1)) !important; // stylelint-disable-line declaration-no-important + } +} diff --git a/site/content/docs/5.1/customize/color.md b/site/content/docs/5.1/customize/color.md index e3d895bef..6a16db1ec 100644 --- a/site/content/docs/5.1/customize/color.md +++ b/site/content/docs/5.1/customize/color.md @@ -102,11 +102,11 @@ Colors ending in `--rgb` provide the `red, green, blue` values for use in `rgb() | **Secondary —** For disabled states, dividers, and lighter text. |
 
 
| `--bs-secondary-color`
`--bs-secondary-color-rgb`
`--bs-secondary-bg`
`--bs-secondary-bg-rgb` | | **Tertiary —** For hovers, accents, wells, and text. |
 
 
| `--bs-tertiary-color`
`--bs-tertiary-color-rgb`
`--bs-tertiary-bg`
`--bs-tertiary-bg-rgb` | | **Border —** For component borders, dividers, and rules. Blends with background colors thanks to `rgba()` values. |
Border color
| `--bs-border-color` | -| **Primary —** Main theme color, used for hyperlinks, focus styles, and component and form active states. |
Primary
| `--bs-primary`
`--bs-primary-rgb` | -| **Success —** Theme color used for positive or successful actions and information. |
Success
| `--bs-success`
`--bs-success-rgb` | -| **Danger —** Theme color used for errors and dangerous actions. |
Danger
| `--bs-danger`
`--bs-danger-rgb` | -| **Warning —** Theme color used for warning messages. |
Warning
| `--bs-warning`
`--bs-warning-rgb` | -| **Info —** Theme color used for neutral and informative content. |
Info
| `--bs-info`
`--bs-info-rgb` | +| **Primary —** Main theme color, used for hyperlinks, focus styles, and component and form active states. |
Primary
| `--bs-primary`
`--bs-primary-rgb` | +| **Success —** Theme color used for positive or successful actions and information. |
Success
| `--bs-success`
`--bs-success-rgb` | +| **Danger —** Theme color used for errors and dangerous actions. |
Danger
| `--bs-danger`
`--bs-danger-rgb` | +| **Warning —** Theme color used for warning messages. |
Warning
| `--bs-warning`
`--bs-warning-rgb` | +| **Info —** Theme color used for neutral and informative content. |
Info
| `--bs-info`
`--bs-info-rgb` | {{< /bs-table >}} ### Theme colors diff --git a/site/content/docs/5.1/helpers/color-background.md b/site/content/docs/5.1/helpers/color-background.md new file mode 100644 index 000000000..98846004d --- /dev/null +++ b/site/content/docs/5.1/helpers/color-background.md @@ -0,0 +1,41 @@ +--- +layout: docs +title: Color & background +description: Set a background color with contrasting foreground color. +group: helpers +toc: false +--- + +Color and background helpers combine the power of our [`.text-*` utilities]({{< docsref "/utilities/colors" >}}) and [`.bg-*` utilities]({{< docsref "/utilities/background" >}}) in one class. Using our Sass `color-contrast()` function, we automatically determine a contrasting `color` for a particular `background-color`. + +{{< example >}} +{{< text-bg.inline >}} +{{- range (index $.Site.Data "theme-colors") }} +
{{ .name | title }} with contrasting color
+{{- end -}} +{{< /text-bg.inline >}} +{{< /example >}} + +Use them in place of combined `.text-*` and `.bg-*` classes, like on badges: + +{{< example >}} +Primary +Info +{{< /example >}} + +Or on cards: + +{{< example >}} +
+
Header
+
+

Some quick example text to build on the card title and make up the bulk of the card's content.

+
+
+
+
Header
+
+

Some quick example text to build on the card title and make up the bulk of the card's content.

+
+
+{{< /example >}} diff --git a/site/data/sidebar.yml b/site/data/sidebar.yml index eb03285c5..cdf0b04d8 100644 --- a/site/data/sidebar.yml +++ b/site/data/sidebar.yml @@ -100,6 +100,7 @@ icon_color: orange pages: - title: Clearfix + - title: Color & background - title: Colored links - title: Ratio - title: Position