卡片

Bootstrap 的卡片提供了一个灵活且可扩展的内容容器,具有多种变体和选项。

Layer: components
Container queries

卡片是灵活且可扩展的内容容器,支持页眉和页脚、多种内容、上下文背景颜色以及额外的显示选项。卡片初始没有固定宽度,因此它们会自然地填满父元素的宽度,或者嵌入到你的网格列中。

PlaceholderImage cap

Card title

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

Go somewhere
HTML
<section class="card" style="max-width: 320px">
  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <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>
    <a href="#" class="btn-solid theme-primary">Go somewhere</a>
  </div>
</section>

工作原理

卡片使用尽可能少的标记和样式构建,但仍能提供大量的控制和自定义能力。

  • 卡片是 Flex 布局容器,因此它们通过 Flex 布局工具类和网格列类提供便捷的对齐方式。

  • .card 没有默认内边距,你需要使用 .card-body 来设置。将其作为修饰符类或子元素,与页眉、页脚、图片等一起使用。这样可以在最少的开销下实现更大的灵活性。

  • 卡片默认没有 margin。根据需要,使用 margin 工具类或 gap 工具类。

  • 卡片可以包含文本、图片、列表以及大多数其他 HTML 内容。

  • 选择适合内容的语义化 HTML。为了简单起见,我们在文档中使用 <div>,但你也可以使用 <section>、<article> 等。

内容类型

主体

卡片的基本构建块是 .card-body。当你需要在卡片内使用带内边距的区块时,请使用它。

这是卡片主体内的一些文本。
HTML
<div class="card">
  <div class="card-body">
    这是卡片主体内的一些文本。
  </div>
</div>

对于简单的卡片,你可以直接在卡片元素上使用 .card-body 类。

这是卡片主体内的一些文本。
HTML
<div class="card card-body">
这是卡片主体内的一些文本。
</div>

标题、文本和链接

卡片主体将其直接子元素按列排列并应用一致的 gap,因此标题和文本无需自己的样式。将这些可选类用作内容挂钩。

  • 对于标题,使用 .card-title。
  • 对于副标题,使用 .card-subtitle。它会减小副标题上方的 gap。
  • 对于文本,使用 .card-text。

根据需要,使用排版和颜色工具类。.card-subtitle 上的颜色工具类会覆盖 --card-subtitle-color。链接无需卡片特定的类。

Example card title

With a card subtitle

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

Card link
HTML
<div class="card" style="max-width: 320px;">
  <div class="card-body">
    <h4 class="card-title">Example card title</h4>
    <p class="card-subtitle fg-3">With a card subtitle</p>
    <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>
    <a href="#">Card link</a>
  </div>
</div>

图片

将图片放置在卡片中的任意位置,并按你的喜好设置样式。

PlaceholderImage cap
Image within the body

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

Last updated 3 mins ago
HTML
<div class="card" style="width: 18rem;">
  <div class="card-body">
    <img src="..." class="card-img" alt="...">
    <h5 class="mt-2 mb-0">Image within the body</h5>
    <p class="card-text fg-2">Some quick example text to build on the card title and make up the bulk of the card’s content.</p>
    <small class="fg-3">Last updated 3 mins ago</small>
  </div>
</div>

使用 .card-img-top 和 .card-img-bottom 圆化图片的顶部和底部角。

PlaceholderImage cap

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.

PlaceholderImage cap
HTML
<div class="card" style="width: 18rem;">
  <img src="..." class="card-img-top" alt="...">
  <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" style="width: 18rem;">
  <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>
  <img src="..." class="card-img-bottom" alt="...">
</div>

列表组

当你的卡片仅包含列表组——没有页眉、页脚或主体——时,单独使用 .list-group。卡片本身已经绘制了外边框,因此卡片内的默认列表组会使边框加倍。

  • An item
  • A second item
  • A third item
HTML
<ul class="list-group" style="width: 18rem;">
  <li class="list-group-item">An item</li>
  <li class="list-group-item">A second item</li>
  <li class="list-group-item">A third item</li>
</ul>

当将列表组与其他卡片子组件混合使用时,添加 .list-group-flush 以去除列表自身的外边框。

Featured
  • An item
  • A second item
  • A third item
HTML
<div class="card" style="width: 18rem;">
  <div class="card-header">
    Featured
  </div>
  <ul class="list-group list-group-flush">
    <li class="list-group-item">An item</li>
    <li class="list-group-item">A second item</li>
    <li class="list-group-item">A third item</li>
  </ul>
</div>
  • An item
  • A second item
  • A third item
HTML
<div class="card" style="width: 18rem;">
  <ul class="list-group list-group-flush">
    <li class="list-group-item">An item</li>
    <li class="list-group-item">A second item</li>
    <li class="list-group-item">A third item</li>
  </ul>
  <div class="card-footer">
    Card footer
  </div>
</div>

综合示例

混合搭配多种内容类型以创建你需要的卡片,或者把一切内容都放进去。下面展示的是图片样式、区块、文本样式和列表组——全部包裹在一个固定宽度的卡片中。

PlaceholderImage cap

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
HTML
<div class="card" style="width: 18rem;">
  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <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>
  <ul class="list-group list-group-flush">
    <li class="list-group-item">An item</li>
    <li class="list-group-item">A second item</li>
    <li class="list-group-item">A third item</li>
  </ul>
  <div class="card-body flex-row gap-4">
    <a href="#">Card link</a>
    <a href="#">Another link</a>
  </div>
</div>

页眉和页脚

在卡片内添加可选的页眉和/或页脚。

Featured

Special title treatment

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

Go somewhere
HTML
<div class="card">
  <div class="card-header">
    Featured
  </div>
  <div class="card-body">
    <h4 class="card-title">Special title treatment</h4>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn-solid theme-primary">Go somewhere</a>
  </div>
</div>

通过为 <h*> 元素添加 .card-header,可以为卡片页眉设置样式。

Featured

Special title treatment

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

Go somewhere
HTML
<div class="card">
  <h5 class="card-header">Featured</h5>
  <div class="card-body">
    <h4 class="card-title">Special title treatment</h4>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn-solid theme-primary">Go somewhere</a>
  </div>
</div>
Quote

A well-known quote, contained in a blockquote element.

HTML
<div class="card">
  <div class="card-header">
    Quote
  </div>
  <div class="card-body">
    <figure>
      <blockquote class="blockquote">
        <p>A well-known quote, contained in a blockquote element.</p>
      </blockquote>
      <figcaption class="blockquote-footer">
        来自某位名人的话 <cite title="Source Title">来源标题</cite>
      </figcaption>
    </figure>
  </div>
</div>
Featured

Special title treatment

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

Go somewhere
HTML
<div class="card text-center">
  <div class="card-header">
    Featured
  </div>
  <div class="card-body">
    <h4 class="card-title">Special title treatment</h4>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn-solid theme-primary mx-auto">Go somewhere</a>
  </div>
  <div class="card-footer fg-2">
    2 days ago
  </div>
</div>

宽度

卡片初始不假定特定的 width,因此除非另有说明,它们将是 100% 宽。你可以根据需要,使用自定义 CSS、网格类、网格 Sass 混入或工具类来更改它。

网格

使用网格,根据需要将卡片包裹在列和行中。

Card title

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

Go somewhere

Card title

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

Go somewhere
HTML
<div class="row">
  <div class="sm:col-6 mb-3 sm:mb-0">
    <div class="card">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
        <a href="#" class="btn-solid theme-primary">Go somewhere</a>
      </div>
    </div>
  </div>
  <div class="sm:col-6">
    <div class="card">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
        <a href="#" class="btn-solid theme-primary">Go somewhere</a>
      </div>
    </div>
  </div>
</div>

工具类

使用我们的少量可用尺寸工具类快速设置卡片的宽度。

Card title

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

Button

Card title

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

Button
HTML
<div class="card w-75 mb-3">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn-solid theme-primary">Button</a>
  </div>
</div>

<div class="card w-50">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn-solid theme-primary">Button</a>
  </div>
</div>

自定义 CSS

在样式表中使用自定义 CSS 或作为内联样式设置宽度。

Card title

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

Go somewhere
HTML
<div class="card" style="width: 18rem;">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn-solid theme-primary">Go somewhere</a>
  </div>
</div>

导航

使用 Bootstrap 的导航组件在卡片的页眉(或区块)中添加一些导航。

Special title treatment

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

Go somewhere
HTML
<div class="card text-center">
  <div class="card-header">
    <ul class="nav nav-tabs card-header-tabs">
      <li class="nav-item">
        <a class="nav-link active" aria-current="true" href="#">Active</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" aria-disabled="true">Disabled</a>
      </li>
    </ul>
  </div>
  <div class="card-body">
    <h5 class="card-title">Special title treatment</h5>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn-solid theme-primary mx-auto">Go somewhere</a>
  </div>
</div>

这也适用于 .nav-pills。

Special title treatment

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

Go somewhere
HTML
<div class="card text-center">
  <div class="card-header">
    <ul class="nav nav-pills">
      <li class="nav-item">
        <a class="nav-link active" href="#">Active</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" aria-disabled="true">Disabled</a>
      </li>
    </ul>
  </div>
  <div class="card-body">
    <h5 class="card-title">Special title treatment</h5>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn-solid theme-primary mx-auto">Go somewhere</a>
  </div>
</div>

图片

卡片包含一些处理图片的选项。可以选择在卡片任一端附加“图片盖”,用卡片内容叠加图片,或者简单地将图片嵌入卡片中。

图片盖

与页眉和页脚类似,卡片可以包含顶部和底部的“图片盖”——位于卡片顶部或底部的图片。

PlaceholderImage cap

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

PlaceholderImage cap
HTML
<div class="card mb-3">
  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p>
  </div>
</div>
<div class="card">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p>
  </div>
  <img src="..." class="card-img-bottom" alt="...">
</div>

图片叠加

将图片转换为卡片背景并叠加卡片文本。根据图片的情况,你可能需要或不需要额外的样式或工具类。

PlaceholderCard image

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

HTML
<div class="card theme-inverse">
  <img src="..." class="card-img" alt="...">
  <div class="card-img-overlay">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    <p class="card-text"><small>Last updated 3 mins ago</small></p>
  </div>
</div>

请注意,内容不应大于图片的高度。如果内容大于图片,内容将显示在图片之外。

卡片行

使用 .card-row 类使卡片水平排列。对于图片盖,使用 .card-img-start 或 .card-img-end 类将图片定位在卡片的(内联)起始或结束位置。

PlaceholderImage

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

HTML
<div class="card card-row" style="max-width: 540px;">
  <img src="..." class="card-img-start" alt="...">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p>
  </div>
</div>

以及反向布局:

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

PlaceholderImage
HTML
<div class="card card-row" style="max-width: 540px;">
  <div class="card-body">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p>
  </div>
  <img src="..." class="card-img-end" alt="...">
</div>

主题变体

使用我们的主题颜色工具类自定义卡片。默认情况下,应用主题颜色时,卡片使用 bg 作为其背景和边框颜色。使用 .card-subtle 交换背景和边框颜色,以获得更柔和的外观。

Primary

Card title

Card text…

Accent

Card title

Card text…

Success

Card title

Card text…

Danger

Card title

Card text…

Warning

Card title

Card text…

Info

Card title

Card text…

Inverse

Card title

Card text…

Secondary

Card title

Card text…

HTML
<div class="card theme-primary">…</div>
<div class="card theme-accent">…</div>
<div class="card theme-success">…</div>
<div class="card theme-danger">…</div>
<div class="card theme-warning">…</div>
<div class="card theme-info">…</div>
<div class="card theme-inverse">…</div>
<div class="card theme-secondary">…</div>
Primary

Card title

Card text…

Accent

Card title

Card text…

Success

Card title

Card text…

Danger

Card title

Card text…

Warning

Card title

Card text…

Info

Card title

Card text…

Inverse

Card title

Card text…

Secondary

Card title

Card text…

HTML
<div class="card card-subtle theme-primary">…</div>
<div class="card card-subtle theme-accent">…</div>
<div class="card card-subtle theme-success">…</div>
<div class="card card-subtle theme-danger">…</div>
<div class="card card-subtle theme-warning">…</div>
<div class="card card-subtle theme-info">…</div>
<div class="card card-subtle theme-inverse">…</div>
<div class="card card-subtle theme-secondary">…</div>

半透明卡片

添加 .card-translucent 以模糊并饱和卡片背景。页眉和页脚背景也会调整,以保持一致的外观。

Translucent card

This card has a translucent background with a backdrop blur effect.

Go somewhere
HTML
<div class="card card-translucent" style="width: 18rem;">
  <div class="card-body">
    <h4 class="card-title">Translucent card</h4>
    <p class="card-text">This card has a translucent background with a backdrop blur effect.</p>
    <a href="#" class="btn-solid theme-primary">Go somewhere</a>
  </div>
</div>
Featured

Card with header

Headers and footers are also made translucent to maintain a consistent look.

Go somewhere
HTML
<div class="card card-translucent" style="width: 18rem;">
  <div class="card-header">
    Featured
  </div>
  <div class="card-body">
    <h4 class="card-title">Card with header</h4>
    <p class="card-text">Headers and footers are also made translucent to maintain a consistent look.</p>
    <a href="#" class="btn-solid theme-primary">Go somewhere</a>
  </div>
  <div class="card-footer fg-2">
    2 days ago
  </div>
</div>

卡片布局

除了为卡片内的内容设置样式外,Bootstrap 还包含一些用于排列一系列卡片的选项。

卡片组

使用卡片组可将卡片渲染为具有等宽等高列的单一连接元素。卡片组初始为堆叠状态,并使用 display: flex; 从 sm 断点开始以统一尺寸连接。

此布局使用容器查询,因此请将卡片组包裹在查询容器中——为父元素添加 .contains-inline 工具类——才能使行布局生效。没有查询容器时,卡片保持堆叠状态。

PlaceholderImage cap

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

PlaceholderImage cap

Card title

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

Last updated 3 mins ago

PlaceholderImage cap

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

HTML
<div class="contains-inline">
  <div class="card-group">
  <div class="card">
    <img src="..." class="card-img-top" alt="...">
    <div class="card-body">
      <h4 class="card-title">Card title</h4>
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p>
    </div>
  </div>
  <div class="card">
    <img src="..." class="card-img-top" alt="...">
    <div class="card-body">
      <h4 class="card-title">Card title</h4>
      <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
      <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p>
    </div>
  </div>
  <div class="card">
    <img src="..." class="card-img-top" alt="...">
    <div class="card-body">
      <h4 class="card-title">Card title</h4>
      <p class="card-text">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.</p>
      <p class="card-text"><small class="fg-2">Last updated 3 mins ago</small></p>
    </div>
  </div>
  </div>
</div>

当卡片组带有页脚时,它们的内容会自动对齐。

PlaceholderImage cap

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.

PlaceholderImage cap

Card title

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

PlaceholderImage cap

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.

HTML
<div class="contains-inline">
  <div class="card-group">
  <div class="card">
    <img src="..." class="card-img-top" alt="...">
    <div class="card-body">
      <h4 class="card-title">Card title</h4>
      <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
    </div>
    <div class="card-footer">
      <small class="fg-2">Last updated 3 mins ago</small>
    </div>
  </div>
  <div class="card">
    <img src="..." class="card-img-top" alt="...">
    <div class="card-body">
      <h4 class="card-title">Card title</h4>
      <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
    </div>
    <div class="card-footer">
      <small class="fg-2">Last updated 3 mins ago</small>
    </div>
  </div>
  <div class="card">
    <img src="..." class="card-img-top" alt="...">
    <div class="card-body">
      <h4 class="card-title">Card title</h4>
      <p class="card-text">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.</p>
    </div>
    <div class="card-footer">
      <small class="fg-2">Last updated 3 mins ago</small>
    </div>
  </div>
  </div>
</div>

网格卡片

使用 Bootstrap 网格系统及其 .row-cols 类来控制每行显示多少网格列(包裹你的卡片)。例如,这里的 .row-cols-1 将卡片布局在一列中,而 .md:row-cols-2 从中等断点起将四张卡片分成等宽的多行。

PlaceholderImage cap

Card title

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

PlaceholderImage cap

Card title

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

PlaceholderImage cap

Card title

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

PlaceholderImage cap

Card title

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

HTML
<div class="row row-cols-1 md:row-cols-2 g-4">
  <div class="col">
    <div class="card">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
    </div>
  </div>
</div>

将其更改为 .row-cols-3,你会看到第四张卡片换行。

PlaceholderImage cap

Card title

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

PlaceholderImage cap

Card title

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

PlaceholderImage cap

Card title

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

PlaceholderImage cap

Card title

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

HTML
<div class="row row-cols-1 md:row-cols-3 g-4">
  <div class="col">
    <div class="card">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
    </div>
  </div>
</div>

当你需要等高时,为卡片添加 .h-100。如果你希望默认等高,可以在 Sass 中设置 $card-height: 100%。

PlaceholderImage cap

Card title

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

PlaceholderImage cap

Card title

This is a short card.

PlaceholderImage cap

Card title

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

PlaceholderImage cap

Card title

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

HTML
<div class="row row-cols-1 md:row-cols-3 g-4">
  <div class="col">
    <div class="card h-100">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card h-100">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a short card.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card h-100">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card h-100">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
    </div>
  </div>
</div>

与卡片组一样,卡片页脚会自动对齐。

PlaceholderImage cap

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.

PlaceholderImage cap

Card title

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

PlaceholderImage cap

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.

HTML
<div class="row row-cols-1 md:row-cols-3 g-4">
  <div class="col">
    <div class="card h-100">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
      </div>
      <div class="card-footer">
        <small class="fg-2">Last updated 3 mins ago</small>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card h-100">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
      </div>
      <div class="card-footer">
        <small class="fg-2">Last updated 3 mins ago</small>
      </div>
    </div>
  </div>
  <div class="col">
    <div class="card h-100">
      <img src="..." class="card-img-top" alt="...">
      <div class="card-body">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">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.</p>
      </div>
      <div class="card-footer">
        <small class="fg-2">Last updated 3 mins ago</small>
      </div>
    </div>
  </div>
</div>

CSS

变量

Cards use local CSS variables on .card for real-time customization. Values for the CSS variables are generated from Sass maps unique to each component and applied to the aforementioned class.

// stylelint-disable-next-line scss/dollar-variable-default
$card-tokens: defaults(
  (
    --card-spacer-y: var(--spacer-6),
    --card-spacer-x: var(--spacer-6),
    --card-subtitle-color: inherit,
    --card-border-width: var(--border-width),
    --card-border-color: var(--border-color),
    --card-border-radius: var(--radius-7),
    --card-box-shadow: none,
    --card-inner-border-radius: calc(var(--card-border-radius) - var(--border-width)),
    --card-cap-padding-y: var(--spacer-3),
    --card-cap-padding-x: var(--spacer-5),
    --card-cap-bg: var(--bg-1),
    --card-cap-color: inherit,
    --card-height: auto,
    --card-color: inherit,
    --card-bg: var(--bg-body),
    --card-img-overlay-padding: var(--card-spacer-y),
    --card-group-margin: #{$grid-gutter-x * .5},
    --card-body-gap: calc(var(--card-spacer-y) * .5),
  ),
  $card-tokens
);