0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00
Bootstrap/site/docs/4.3/components/card.md
Mark Otto 1ded0d6a4e
Release v4.3.0 (#28228)
* Prep for v4.3.0

* More updates for v4.3.0.

* rerun to build docs source map
2019-02-11 11:15:34 -08:00

28 KiB

layout title description group toc
docs Cards Bootstrap's cards provide a flexible and extensible content container with multiple variants and options. components true

About

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 [spacing utilities]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/spacing/) 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.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image 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
{% endcapture %} {% include example.html content=example %}

Content types

Cards support a wide variety of content, including images, text, list groups, links, and more. Below are examples of what's supported.

Body

The building block of a card is the .card-body. Use it whenever you need a padded section within a card.

{% capture example %}

This is some text within a card body.
{% endcapture %} {% include example.html content=example %}

Card titles are used by adding .card-title to a <h*> tag. In the same way, links are added and placed next to each other by adding .card-link to an <a> tag.

Subtitles are used by adding a .card-subtitle to a <h*> 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.

{% capture example %}

Card title
Card subtitle

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

Card link Another link
{% endcapture %} {% include example.html content=example %}

Images

.card-img-top places an image to the top of the card. With .card-text, text can be added to the card. Text within .card-text can also be styled with the standard HTML tags.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image cap" %}

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

{% endcapture %} {% include example.html content=example %}

List groups

Create lists of content in a card with a flush list group.

{% capture example %}

  • Cras justo odio
  • Dapibus ac facilisis in
  • Vestibulum at eros
{% endcapture %} {% include example.html content=example %}

{% capture example %}

Featured
  • Cras justo odio
  • Dapibus ac facilisis in
  • Vestibulum at eros
{% endcapture %} {% include example.html content=example %}

Kitchen sink

Mix and match multiple content types to create the card you need, or throw everything in there. Shown below are image styles, blocks, text styles, and a list group—all wrapped in a fixed-width card.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image cap" %}
Card title

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

  • Cras justo odio
  • Dapibus ac facilisis in
  • Vestibulum at eros
{% endcapture %} {% include example.html content=example %}

Add an optional header and/or footer within a card.

{% capture example %}

Featured
Special title treatment

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

Go somewhere
{% endcapture %} {% include example.html content=example %}

Card headers can be styled by adding .card-header to <h*> elements.

{% capture example %}

Featured
Special title treatment

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

Go somewhere
{% endcapture %} {% include example.html content=example %}

{% capture example %}

Quote

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.

Someone famous in Source Title
{% endcapture %} {% include example.html content=example %}

{% capture example %}

Featured
Special title treatment

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

Go somewhere
2 days ago
{% endcapture %} {% include example.html content=example %}

Sizing

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

Using the grid, wrap cards in columns and rows as needed.

{% capture example %}

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
{% endcapture %} {% include example.html content=example %}

Using utilities

Use our handful of [available sizing utilities]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/sizing/) to quickly set a card's width.

{% capture example %}

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
{% endcapture %} {% include example.html content=example %}

Using custom CSS

Use custom CSS in your stylesheets or as inline styles to set a width.

{% capture example %}

Special title treatment

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

Go somewhere
{% endcapture %} {% include example.html content=example %}

Text alignment

You can quickly change the text alignment of any card—in its entirety or specific parts—with our [text align classes]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/text/#text-alignment).

{% capture example %}

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
{% endcapture %} {% include example.html content=example %}

Navigation

Add some navigation to a card's header (or block) with Bootstrap's [nav components]({{ site.baseurl }}/docs/{{ site.docs_version }}/components/navs/).

{% capture example %}

Special title treatment

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

Go somewhere
{% endcapture %} {% include example.html content=example %}

{% capture example %}

Special title treatment

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

Go somewhere
{% endcapture %} {% include example.html content=example %}

Images

Cards include a few options for working with images. Choose from appending "image caps" at either end of a card, overlaying images with card content, or simply embedding the image in a card.

Image caps

Similar to headers and footers, cards can include top and bottom "image caps"—images at the top or bottom of a card.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image 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

{% include icons/placeholder.svg width="100%" height="180" class="card-img-bottom" text="Image cap" %}
{% endcapture %} {% include example.html content=example %}

Image overlays

Turn an image into a card background and overlay your card's text. Depending on the image, you may or may not need additional styles or utilities.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="270" class="bd-placeholder-img-lg card-img" text="Card 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

{% endcapture %} {% include example.html content=example %}

{% capture callout %} 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. {% endcapture %} {% include callout.html content=callout type="info" %}

Horizontal

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 .no-gutters and use .col-md-* classes to make the card horizontal at the md breakpoint. Further adjustments may be needed depending on your card content.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="250" class="" text="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

{% endcapture %} {% include example.html content=example %}

Card styles

Cards include various options for customizing their backgrounds, borders, and color.

Background and color

Use [text and background utilities]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/colors/) to change the appearance of a card.

{% capture example %} {% for color in site.data.theme-colors %}

Header
{{ color.name | capitalize }} card title

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

{% endfor %} {% endcapture %} {% include example.html content=example %}

{% include callout-warning-color-assistive-technologies.md %}

Border

Use [border utilities]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/borders/) to change just the border-color of a card. Note that you can put .text-{color} classes on the parent .card or a subset of the card's contents as shown below.

{% capture example %} {% for color in site.data.theme-colors %}

Header
{{ color.name | capitalize }} card title

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

{% endfor %} {% endcapture %} {% include example.html content=example %}

Mixins utilities

You can also change the borders on the card header and footer as needed, and even remove their background-color with .bg-transparent.

{% capture example %}

Header
Success card title

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

Footer
{% endcapture %} {% include example.html content=example %}

Card layout

In addition to styling the content within cards, Bootstrap includes a few options for laying out series of cards. For the time being, these layout options are not yet responsive.

Card groups

Use card groups to render cards as a single, attached element with equal width and height columns. Card groups use display: flex; to achieve their uniform sizing.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image 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

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image cap" %}
Card title

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

Last updated 3 mins ago

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image 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

{% endcapture %} {% include example.html content=example %}

When using card groups with footers, their content will automatically line up.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image 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
{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image cap" %}
Card title

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

Last updated 3 mins ago
{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image 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
{% endcapture %} {% include example.html content=example %}

Card decks

Need a set of equal width and height cards that aren't attached to one another? Use card decks.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="200" class="card-img-top" text="Image 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.

Last updated 3 mins ago

{% include icons/placeholder.svg width="100%" height="200" class="card-img-top" text="Image cap" %}
Card title

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

Last updated 3 mins ago

{% include icons/placeholder.svg width="100%" height="200" class="card-img-top" text="Image 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

{% endcapture %} {% include example.html content=example %}

Just like with card groups, card footers in decks will automatically line up.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image 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
{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image cap" %}
Card title

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

Last updated 3 mins ago
{% include icons/placeholder.svg width="100%" height="180" class="card-img-top" text="Image 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
{% endcapture %} {% include example.html content=example %}

Card columns

Cards can be organized into Masonry-like columns with just CSS by wrapping them in .card-columns. Cards are built with CSS column properties instead of flexbox for easier alignment. Cards are ordered from top to bottom and left to right.

Heads up! Your mileage with card columns may vary. To prevent cards breaking across columns, we must set them to display: inline-block as column-break-inside: avoid isn't a bulletproof solution yet.

{% capture example %}

{% include icons/placeholder.svg width="100%" height="160" class="card-img-top" text="Image cap" %}
Card title that wraps to a new line

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

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.

Someone famous in Source Title
{% include icons/placeholder.svg width="100%" height="160" class="card-img-top" text="Image cap" %}
Card title

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

Last updated 3 mins ago

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat.

Someone famous in Source Title
Card title

This card has a regular title and short paragraphy of text below it.

Last updated 3 mins ago

{% include icons/placeholder.svg width="100%" height="260" class="card-img" text="Card image" %}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.

Someone famous in Source Title
Card title

This is another card with title and supporting text below. This card has some additional content to make it slightly taller overall.

Last updated 3 mins ago

{% endcapture %} {% include example.html content=example %}

Card columns can also be extended and customized with some additional code. Shown below is an extension of the .card-columns class using the same CSS we use—CSS columns— to generate a set of responsive tiers for changing the number of columns.

{% highlight scss %} .card-columns { @include media-breakpoint-only(lg) { column-count: 4; } @include media-breakpoint-only(xl) { column-count: 5; } } {% endhighlight %}