]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Add new text-bg-color utilities
authorMark Otto <markdotto@gmail.com>
Thu, 28 Apr 2022 03:40:23 +0000 (20:40 -0700)
committerMark Otto <otto@github.com>
Sat, 30 Apr 2022 19:55:27 +0000 (12:55 -0700)
scss/_helpers.scss
scss/helpers/_color-bg.scss [new file with mode: 0644]
site/content/docs/5.1/helpers/color-background.md [new file with mode: 0644]
site/data/sidebar.yml

index 4a989f5a5c5614789bc8d06ca03f9b4077e7b692..644b693fbc9195622b1e56129c8b5e03d19b0e4c 100644 (file)
@@ -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 (file)
index 0000000..80ba863
--- /dev/null
@@ -0,0 +1,10 @@
+// stylelint-disable declaration-no-important, function-name-case
+
+// All-caps `RGBA()` function used because of this Sass bug: https://github.com/sass/node-sass/issues/2251
+@each $color, $value in $theme-colors {
+  $color-rgb: to-rgb($value);
+  .text-bg-#{$color} {
+    color: color-contrast($value) !important;
+    background-color: RGBA($color-rgb, var(--#{$prefix}bg-opacity, 1)) !important;
+  }
+}
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 (file)
index 0000000..c417484
--- /dev/null
@@ -0,0 +1,52 @@
+---
+layout: docs
+title: Color & background
+description: Set a background color with contrasting foreground color.
+group: helpers
+toc: true
+added: "5.2"
+---
+
+## Overview
+
+{{< added-in "5.2.0" >}}
+
+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`.
+
+{{< callout warning >}}
+**Heads up!** There's currently no support for a CSS-native `color-contrast` function, so we use our own via Sass. This means that customizing our theme colors via CSS variables may cause color contrast issues with these utilities.
+{{< /callout >}}
+
+{{< example >}}
+{{< text-bg.inline >}}
+{{- range (index $.Site.Data "theme-colors") }}
+<div class="text-bg-{{ .name }} p-3">{{ .name | title }} with contrasting color</div>
+{{- end -}}
+{{< /text-bg.inline >}}
+{{< /example >}}
+
+## With components
+
+Use them in place of combined `.text-*` and `.bg-*` classes, like on [badges]({{< docsref "/components/badge#background-colors" >}}):
+
+{{< example >}}
+<span class="badge text-bg-primary">Primary</span>
+<span class="badge text-bg-info">Info</span>
+{{< /example >}}
+
+Or on [cards]({{< docsref "/components/card#background-and-color" >}}):
+
+{{< example >}}
+<div class="card text-bg-primary mb-3" style="max-width: 18rem;">
+  <div class="card-header">Header</div>
+  <div class="card-body">
+    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+  </div>
+</div>
+<div class="card text-bg-info mb-3" style="max-width: 18rem;">
+  <div class="card-header">Header</div>
+  <div class="card-body">
+    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+  </div>
+</div>
+{{< /example >}}
index eb03285c5f4fd6cddec23179952d9375abb61b8d..cdf0b04d8b8102b04177387796e9f18033fcf1d2 100644 (file)
   icon_color: orange
   pages:
     - title: Clearfix
+    - title: Color & background
     - title: Colored links
     - title: Ratio
     - title: Position