From: Mark Otto Date: Wed, 28 May 2025 04:58:30 +0000 (-0700) Subject: Redo aspect ratio docs X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4634b58cd8030273cced083976745cc1be227d47;p=thirdparty%2Fbootstrap.git Redo aspect ratio docs --- diff --git a/scss/_utilities.scss b/scss/_utilities.scss index 75e3e1a725..0b287d86dc 100644 --- a/scss/_utilities.scss +++ b/scss/_utilities.scss @@ -17,8 +17,15 @@ $utilities: map.merge( ), // scss-docs-end utils-vertical-align // scss-docs-start utils-aspect-ratio - "aspect-ratio": ( + "aspect-ratio-attr": ( + selector: "attr-includes", + class: "ratio-", property: aspect-ratio, + values: var(--#{$prefix}ratio), + ), + "aspect-ratio": ( + // property: aspect-ratio, + property: --#{$prefix}ratio, class: ratio, values: $aspect-ratios ), diff --git a/scss/_variables.scss b/scss/_variables.scss index 0a2d6040fc..c7e9b45b4b 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -307,10 +307,10 @@ $transition-collapse-width: width .35s ease !default; // scss-docs-start aspect-ratios $aspect-ratios: ( "auto": auto, - "4x3": 4 / 3, - "1x1": 1 / 1, - "16x9": 16 / 9, - "21x9": 21 / 9 + "4x3": #{"4 / 3"}, + "1x1": #{"1 / 1"}, + "16x9": #{"16 / 9"}, + "21x9": #{"21 / 9"} ) !default; // scss-docs-end aspect-ratios diff --git a/site/src/content/docs/utilities/aspect-ratio.mdx b/site/src/content/docs/utilities/aspect-ratio.mdx index c201174400..6fac6f0855 100644 --- a/site/src/content/docs/utilities/aspect-ratio.mdx +++ b/site/src/content/docs/utilities/aspect-ratio.mdx @@ -1,67 +1,68 @@ --- -title: Aspect Ratio -description: Use generated pseudo elements to make an element maintain the aspect ratio of your choosing. Perfect for responsively handling video or slideshow embeds based on the width of the parent. +title: Aspect ratio +description: Make elements maintain specific aspect ratios. Perfect for handling videos, slideshow embeds, and more based on the width of the parent. toc: true --- -Use the ratio utility to manage the aspect ratios of content like ``} /> +Heads up—you can omit `frameborder="0"` on your ``} /> -Aspect ratios can be customized with modifier classes. By default the following ratio classes are provided: +Swap the `.ratio-*` class for a different aspect ratio.
Auto
-
1x1
+
1×1
-
4x3
+
4×3
-
16x9
+
16×9
-
21x9
+
21×9
`} /> -## Custom ratios - -{/* mdo-do: do we bring these back? - -Each `.ratio-*` class includes a CSS custom property (or CSS variable) in the selector. You can override this CSS variable to create custom aspect ratios on the fly with some quick math on your part. +## How it works -For example, to create a 2x1 aspect ratio, set `--bs-aspect-ratio: 50%` on the `.ratio`. +Aspect ratios are a combination pairing of attribute and class utilities. The attribute utility sets a CSS variable to all `.ratio-` classes, while the specific ratio utility class sets the value for that variable. - -
2x1
- `} /> - -This CSS variable makes it easy to modify the aspect ratio across breakpoints. The following is 4x3 to start, but changes to a custom 2x1 at the medium breakpoint. +```css +[class*="ratio-"] { + aspect-ratio: var(--bs-ratio); +} -```scss -.ratio-4x3 { - @include media-breakpoint-up(md) { - --bs-aspect-ratio: 50%; // 2x1 - } +.ratio-1x1 { + --bs-ratio: 1 / 1; } ``` - -
4x3, then 2x1
+## Custom ratios + +Because of the combination of attribute and class utilities, you can use custom ratios by setting the CSS variable to the desired ratio. + + +
4×1
`} /> -*/} ## Sass map diff --git a/site/src/scss/_component-examples.scss b/site/src/scss/_component-examples.scss index d1b1f66ab5..f17e178fa3 100644 --- a/site/src/scss/_component-examples.scss +++ b/site/src/scss/_component-examples.scss @@ -183,13 +183,15 @@ // Ratio helpers .bd-example-ratios { [class*="ratio"] { + color-scheme: dark; display: flex; align-items: center; justify-content: center; margin-bottom: 1rem; - color: var(--bs-secondary-color); - background-color: var(--bs-tertiary-bg); + color: var(--bs-fg-3); + background-color: var(--bs-bg-1); border: var(--bs-border-width) solid var(--bs-border-color); + @include border-radius(var(--bs-border-radius)); } }