From 983038bb57acffbddfe1852ac2659ad613857a0a Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Sun, 21 Dec 2025 12:25:12 -0800 Subject: [PATCH 1/4] Start process of redoing Cards --- scss/_card.scss | 98 +++++++++-------------- site/src/content/docs/components/card.mdx | 95 ++++++++++------------ 2 files changed, 81 insertions(+), 112 deletions(-) diff --git a/scss/_card.scss b/scss/_card.scss index 90beddccc2cb..817fb08bd756 100644 --- a/scss/_card.scss +++ b/scss/_card.scss @@ -7,23 +7,23 @@ // scss-docs-start card-variables $card-spacer-y: $spacer !default; $card-spacer-x: $spacer !default; -$card-title-spacer-y: $spacer * .5 !default; -$card-title-color: null !default; $card-subtitle-color: null !default; $card-border-width: var(--border-width) !default; $card-border-color: var(--border-color-translucent) !default; -$card-border-radius: var(--border-radius) !default; +$card-border-radius: var(--border-radius-lg) !default; $card-box-shadow: null !default; $card-inner-border-radius: calc(#{$card-border-radius} - #{$card-border-width}) !default; -$card-cap-padding-y: $card-spacer-y * .5 !default; +$card-cap-padding-y: $card-spacer-y !default; $card-cap-padding-x: $card-spacer-x !default; -$card-cap-bg: rgba(var(--body-color-rgb), .03) !default; +$card-cap-bg: var(--bg-1) !default; $card-cap-color: null !default; $card-height: null !default; $card-color: null !default; $card-bg: var(--bg-body) !default; $card-img-overlay-padding: $spacer !default; $card-group-margin: $grid-gutter-width * .5 !default; + +$card-body-gap: $card-spacer-y * .5 !default; // scss-docs-end card-variables @layer components { @@ -31,8 +31,6 @@ $card-group-margin: $grid-gutter-width * .5 !default; // scss-docs-start card-css-vars --card-spacer-y: #{$card-spacer-y}; --card-spacer-x: #{$card-spacer-x}; - --card-title-spacer-y: #{$card-title-spacer-y}; - --card-title-color: #{$card-title-color}; --card-subtitle-color: #{$card-subtitle-color}; --card-border-width: #{$card-border-width}; --card-border-color: #{$card-border-color}; @@ -48,6 +46,7 @@ $card-group-margin: $grid-gutter-width * .5 !default; --card-bg: #{$card-bg}; --card-img-overlay-padding: #{$card-img-overlay-padding}; --card-group-margin: #{$card-group-margin}; + --card-body-gap: #{$card-body-gap}; // scss-docs-end card-css-vars position: relative; @@ -58,80 +57,64 @@ $card-group-margin: $grid-gutter-width * .5 !default; color: var(--color-body); word-wrap: break-word; background-color: var(--card-bg); - background-clip: border-box; - border: var(--card-border-width) solid var(--card-border-color); - @include border-radius(var(--card-border-radius)); + // border: var(--card-border-width) solid var(--card-border-color); + // @include border-radius(var(--card-border-radius)); @include box-shadow(var(--card-box-shadow)); > hr { margin-inline: 0; } - - > .list-group { - border-block: inherit; - - &:first-child { - border-block-start-width: 0; - @include border-top-radius(var(--card-inner-border-radius)); - } - - &:last-child { - border-block-end-width: 0; - @include border-bottom-radius(var(--card-inner-border-radius)); - } - } - - // Due to specificity of the above selector (`.card > .list-group`), we must - // use a child selector here to prevent double borders. - > .card-header + .list-group, - > .list-group + .card-footer { - border-block-start: 0; - } } .card-body { + display: flex; // Enable `flex-grow: 1` for decks and groups so that card blocks take up // as much space as possible, ensuring footers are aligned to the bottom. flex: 1 1 auto; + flex-direction: column; + gap: var(--card-body-gap); + align-items: flex-start; padding: var(--card-spacer-y) var(--card-spacer-x); color: var(--card-color); - } + border: solid var(--card-border-color); + border-width: 0 var(--card-border-width); - .card-title { - margin-bottom: var(--card-title-spacer-y); - color: var(--card-title-color); + > * { + margin-block: 0; + } } - .card-subtitle { - margin-top: calc(-.5 * var(--card-title-spacer-y)); - margin-bottom: 0; - color: var(--card-subtitle-color); - } + .card-body, + .card-list { + // border: var(--card-border-width) solid var(--card-border-color); + border: solid var(--card-border-color); + border-width: 0 var(--card-border-width); - .card-text:last-child { - margin-bottom: 0; - } + &:first-child { + @include border-top-radius(var(--card-border-radius)); + border-top-width: var(--card-border-width); + } - .card-link { - &:hover { - text-decoration: none; + &:last-child { + @include border-bottom-radius(var(--card-border-radius)); + border-bottom-width: var(--card-border-width); } - + .card-link { - margin-inline-start: var(--card-spacer-x); + &:not(:first-child):not(:last-child) { + border-block-end-width: var(--card-border-width); } } - // - // Optional textual caps - // + .card-subtitle { + margin-top: calc(var(--card-body-gap) * -.5); + } .card-header { padding: var(--card-cap-padding-y) var(--card-cap-padding-x); margin-bottom: 0; // Removes the default margin-bottom of color: var(--card-cap-color); background-color: var(--card-cap-bg); - border-block-end: var(--card-border-width) solid var(--card-border-color); + border: var(--card-border-width) solid var(--card-border-color); &:first-child { @include border-radius(var(--card-inner-border-radius) var(--card-inner-border-radius) 0 0); @@ -142,7 +125,7 @@ $card-group-margin: $grid-gutter-width * .5 !default; padding: var(--card-cap-padding-y) var(--card-cap-padding-x); color: var(--card-cap-color); background-color: var(--card-cap-bg); - border-block-start: var(--card-border-width) solid var(--card-border-color); + border: var(--card-border-width) solid var(--card-border-color); &:last-child { @include border-radius(0 0 var(--card-inner-border-radius) var(--card-inner-border-radius)); @@ -154,7 +137,8 @@ $card-group-margin: $grid-gutter-width * .5 !default; // Header navs // - .card-header-tabs { + // Combined selector because of specificity match with `.nav` base class + .nav.card-header-tabs { margin-inline: calc(-.5 * var(--card-cap-padding-x)); margin-bottom: calc(-1 * var(--card-cap-padding-y)); border-block-end: 0; @@ -165,10 +149,6 @@ $card-group-margin: $grid-gutter-width * .5 !default; } } - .card-header-pills { - margin-inline: calc(-.5 * var(--card-cap-padding-x)); - } - // Card image .card-img-overlay { position: absolute; @@ -181,6 +161,8 @@ $card-group-margin: $grid-gutter-width * .5 !default; .card-img-top, .card-img-bottom { width: 100%; // Required because we use flexbox and this inherently applies align-self: stretch + outline: var(--card-border-width) solid var(--card-border-color); + outline-offset: calc(var(--card-border-width) * -1); } .card-img, diff --git a/site/src/content/docs/components/card.mdx b/site/src/content/docs/components/card.mdx index 5ba69abe5e89..6b844cee2d54 100644 --- a/site/src/content/docs/components/card.mdx +++ b/site/src/content/docs/components/card.mdx @@ -6,25 +6,31 @@ toc: true import { getData } from '@libs/data' -## About +Cards are flexible and extensible content containers. They include options for headers and footers, a wide variety of content, contextual background colors, and powerful display options. **Cards have no fixed width to start**, so they’ll naturally fill the full width of its parent element, or slot into your grid columns. This is easily customized with our various [sizing options](#sizing). -A **card** is a flexible and extensible content container. It includes options for headers and footers, a wide variety of content, contextual background colors, and powerful display options. If you’re familiar with Bootstrap 3, cards replace our old panels, wells, and thumbnails. Similar functionality to those components is available as modifier classes for cards. - -## Example - -Cards are built with as little markup and styles as possible, but still manage to deliver a ton of control and customization. Built with flexbox, they offer easy alignment and mix well with other Bootstrap components. They have no `margin` by default, so use [margin utilities]([[docsref:/utilities/margin]]) as needed. - -Below is an example of a basic card with mixed content and a fixed width. Cards have no fixed width to start, so they’ll naturally fill the full width of its parent element. This is easily customized with our various [sizing options](#sizing). - - +
-
Card title
+

Card title

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

- Go somewhere + Go somewhere
`} /> +## How it works + +Cards are built with as little markup and styles as possible, but still manage to deliver a ton of control and customization. + +- Cards are built with flexbox, so they offer easy alignment via [flexbox utilities]([[docsref:/utilities/flex]]) and [grid column classes]([[docsref:/layout/grid#column-classes]]). + +- Cards have no `margin` by default, so use [margin utilities]([[docsref:/utilities/margin]]) as needed. + +- Cards are broken down into three categories of sub-components: header, body, and footer. Headers and footers are optional while the body is required. Images can also serve as headers and footers. + +- Card and card body are both `flex` containers, so content can be aligned and stretched as needed with utilities and whatever HTML you require. + +- Cards can have nearly any content, including text, images, lists, and more. + ## Content types Cards support a wide variety of content, including images, text, list groups, links, and more. Below are examples of what’s supported. @@ -41,48 +47,57 @@ The building block of a card is the `.card-body`. Use it whenever you need a pad ### Titles, text, and links -Card titles are used by adding `.card-title` to a `` tag. In the same way, links are added and placed next to each other by adding `.card-link` to an `` tag. +Titles, text, and links within cards all have required class names for managing alignment. Size and color is up to you to manage. -Subtitles are used by adding a `.card-subtitle` to a `` tag. If the `.card-title` and the `.card-subtitle` items are placed in a `.card-body` item, the card title and subtitle are aligned nicely. +- For a title, use `.card-title`. +- For a subtitle, use `.card-subtitle`. This uses a negative margin to position itself closer to the title. +- For text, use `.card-text`. This removes block margins from the element. `} /> ### Images -`.card-img-top` and `.card-img-bottom` respectively set the top and bottom corners rounded to match the card’s borders. With `.card-text`, text can be added to the card. Text within `.card-text` can also be styled with the standard HTML tags. +Use `.card-img-top` and `.card-img-bottom` to round the top and bottom corners of the image. - +

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

+ +
+
+

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

+
+
`} /> ### List groups -Create lists of content in a card with a flush list group. +When your card only contains a list group—no header, footer, or body—simply use a `.list-group` if possible. Card borders are applied to individual card sub-components, so in this case, you‘ll have the list group’s default border. -
    +
    • An item
    • A second item
    • A third item
    `} /> +When combined with other card sub-components, use `.card-list` to manage borders and rounded corners. +
    Featured
    -
      +
      • An item
      • A second item
      • A third item
      • @@ -90,7 +105,7 @@ Create lists of content in a card with a flush list group. `} /> -
          +
          • An item
          • A second item
          • A third item
          • @@ -110,7 +125,7 @@ Mix and match multiple content types to create the card you need, or throw every
            Card title

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

            -
              +
              • An item
              • A second item
              • A third item
              • @@ -238,34 +253,6 @@ Use custom CSS in your stylesheets or as inline styles to set a width. `} /> -## Text alignment - -You can quickly change the text alignment of any card—in its entirety or specific parts—with our [text align classes]([[docsref:/utilities/text-alignment]]). - - -
                -
                Special title treatment
                -

                With supporting text below as a natural lead-in to additional content.

                - Go somewhere -
                - - -
                -
                -
                Special title treatment
                -

                With supporting text below as a natural lead-in to additional content.

                - Go somewhere -
                -
                - -
                -
                -
                Special title treatment
                -

                With supporting text below as a natural lead-in to additional content.

                - Go somewhere -
                -
                `} /> - ## Navigation Add some navigation to a card’s header (or block) with Bootstrap’s [nav components]([[docsref:/components/navs-tabs]]). @@ -293,7 +280,7 @@ Add some navigation to a card’s header (or block) with Bootstrap’s [nav comp
                -
                -
                Special title treatment
                +

                Special title treatment

                With supporting text below as a natural lead-in to additional content.

                Go somewhere
                @@ -156,7 +156,7 @@ Card headers can be styled by adding `.card-header` to `` elements.
                Featured
                -
                Special title treatment
                +

                Special title treatment

                With supporting text below as a natural lead-in to additional content.

                Go somewhere
                @@ -183,7 +183,7 @@ Card headers can be styled by adding `.card-header` to `` elements. Featured
                -
                Special title treatment
                +

                Special title treatment

                With supporting text below as a natural lead-in to additional content.

                Go somewhere
                @@ -192,11 +192,11 @@ Card headers can be styled by adding `.card-header` to `` elements. `} /> -## Sizing +## Width Cards assume no specific `width` to start, so they’ll be 100% wide unless otherwise stated. You can change this as needed with custom CSS, grid classes, grid Sass mixins, or utilities. -### Using grid markup +### Grid Using the grid, wrap cards in columns and rows as needed. @@ -204,7 +204,7 @@ Using the grid, wrap cards in columns and rows as needed.
                -
                Special title treatment
                +

                Card title

                With supporting text below as a natural lead-in to additional content.

                Go somewhere
                @@ -213,7 +213,7 @@ Using the grid, wrap cards in columns and rows as needed.
                -
                Special title treatment
                +

                Card title

                With supporting text below as a natural lead-in to additional content.

                Go somewhere
                @@ -221,13 +221,13 @@ Using the grid, wrap cards in columns and rows as needed.
                `} /> -### Using utilities +### Utilities Use our handful of [available sizing utilities]([[docsref:/utilities/width]]) to quickly set a card’s width.
                -
                Card title
                +

                Card title

                With supporting text below as a natural lead-in to additional content.

                Button
                @@ -235,19 +235,19 @@ Use our handful of [available sizing utilities]([[docsref:/utilities/width]]) to
                -
                Card title
                +

                Card title

                With supporting text below as a natural lead-in to additional content.

                Button
                `} /> -### Using custom CSS +### Custom CSS Use custom CSS in your stylesheets or as inline styles to set a width.
                -
                Special title treatment
                +

                Card title

                With supporting text below as a natural lead-in to additional content.

                Go somewhere
                @@ -278,6 +278,8 @@ Add some navigation to a card’s header (or block) with Bootstrap’s [nav comp
                `} /> +This works with `.nav-pills` as well. +
                -
                Card title
                +

                Card title

                This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.

                Last updated 3 mins ago

                @@ -331,7 +333,7 @@ Turn an image into a card background and overlay your card’s text. Depending o
                -
                Card title
                +

                Card title

                This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.

                Last updated 3 mins ago

                @@ -341,23 +343,28 @@ Turn an image into a card background and overlay your card’s text. Depending o Note that content should not be larger than the height of the image. If content is larger than the image the content will be displayed outside the image. -## Horizontal +## Card row -Using a combination of grid and utility classes, cards can be made horizontal in a mobile-friendly and responsive way. In the example below, we remove the grid gutters with `.g-0` and use `.col-md-*` classes to make the card horizontal at the `md` breakpoint. Further adjustments may be needed depending on your card content. +Use the `.card-row` class to make a card horizontal. For image caps, use the `.card-img-start` or `.card-img-end` class to position the image at the (inline) start or end position of the card. - -
                -
                - -
                -
                -
                -
                Card title
                -

                This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.

                -

                Last updated 3 mins ago

                -
                -
                + + +
                +

                Card title

                +

                This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.

                +

                Last updated 3 mins ago

                +
                +
                `} /> + +And with the reverse layout: + + +
                +

                Card title

                +

                This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.

                +

                Last updated 3 mins ago

                +
                `} /> ## Card styles @@ -371,7 +378,7 @@ Set a `background-color` with contrasting foreground `color` with [our `.text-bg `
                Header
                -
                ${themeColor.title} card title
                +

                ${themeColor.title} card title

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

                `)} /> @@ -385,7 +392,7 @@ Use [border utilities]([[docsref:/utilities/border]]) to change just the `border `
                Header
                -
                ${themeColor.title} card title
                +

                ${themeColor.title} card title

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

                `)} /> @@ -397,7 +404,7 @@ You can also change the borders on the card header and footer as needed, and eve
                Header
                -
                Success card title
                +

                Success card title

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

                @@ -415,7 +422,7 @@ Use card groups to render cards as a single, attached element with equal width a
                -
                Card title
                +

                Card title

                This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.

                Last updated 3 mins ago

                @@ -423,7 +430,7 @@ Use card groups to render cards as a single, attached element with equal width a
                -
                Card title
                +

                Card title

                This card has supporting text below as a natural lead-in to additional content.

                Last updated 3 mins ago

                @@ -431,7 +438,7 @@ Use card groups to render cards as a single, attached element with equal width a
                -
                Card title
                +

                Card title

                This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.

                Last updated 3 mins ago

                @@ -444,7 +451,7 @@ When using card groups with footers, their content will automatically line up.
                -
                Card title
                +

                Card title

                This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.