Bootstrap Cards

You may utilize the Bootstrap card components after watching this tutorial.

Using the Bootstrap Cards

The Bootstrap card is a versatile and adaptable container for content. It offers options for headers and footers, a wide range of content types, contextual background colors, and flexible display choices. The card component replaces the panel, well, and thumbnail components from the old Bootstrap 3 version.

Creating a Basic Card

The card markup is straightforward. The outer wrapper requires the base class .card, and content can be placed inside the .card-body element. The following example demonstrates how to create a card with a picture, mixed with some text content and a button.

<div class="m-4">
    <div class="card" style="width: 300px;">
        <img src="sample.png" class="card-img-top" alt="Sample Image">
        <div class="card-body text-center">
            <h5 class="card-title">Alice Liddel</h5>
            <p class="card-text">Alice is a freelance web designer and developer based in London. She is specialized in HTML5, CSS3, JavaScript, Bootstrap, etc.</p>
            <a href="#" class="btn btn-primary">View Profile</a>
        </div>
    </div>
</div>

Note: Cards do not have a fixed width; they occupy the full width of their parent element. If you need a fixed-width card, you can apply the width property to the card yourself. Additionally, cards have no margin by default, but you can use spacing utility classes if needed.


Content Types for Card Component

The card component supports a wide variety of content, including images, text, list groups, links, navs, and more. Here are examples of what is supported by the card:

Body Only Card

You can simply use .card with .card-body inside whenever you need to create a padded box.

<div class="m-4">
    <div class="card">
        <div class="card-body">This text is enclosed in a box with padding.</div>
    </div>
</div>

Card with Titles, Text, and Links

Furthermore, you can include titles and links inside the card along with text, as shown below:

<div class="m-4">
    <div class="card" style="width: 300px;">
        <div class="card-body">
            <h5 class="card-title">Taj Mahal</h5>
            <h6 class="card-subtitle mb-3 text-muted"> Agra, Uttar Pradesh, India.</h6>
            <p class="card-text">Built: 1631–1653 Taj Mahal is one of the most iconic landmarks in the world</p>
            <a href="#" class="card-link">View pictures</a>
            <a href="#" class="card-link">Learn more</a>
        </div>
    </div>
</div>

Card with Header and Footer

You can also add a header and footer within your cards using the .card-header and .card-footer class, respectively. The following example demonstrates this:

<div class="m-4">
    <div class="card text-center">
        <div class="card-header">Featured</div>
        <div class="card-body">
            <h5 class="card-title">NASA Launched Solar Probe</h5>
            <p class="card-text">In order to conduct studies of the outer solar corona, NASA deployed the Parker space probe in 2018. It is the first mission to ever "touch" the Sun.</p>
            <a href="#" class="btn btn-primary">Know more</a>
        </div>
        <div class="card-footer text-muted">3 years ago</div>
    </div>
</div>

Tip: You can use text-align utility classes such as .text-center and .text-end to align the card's content to the center and right end, respectively. By default, the content is left-aligned.

Placing List Groups within Card

List groups can also be placed inside the card alongside other content types, as depicted here:

<div class="m-4">
    <div class="card" style="width: 300px;">
        <div class="card-header">Featured</div>
        <ul class="list-group list-group-flush">
            <li class="list-group-item">Part 1</li>
            <li class="list-group-item">Part 2</li>
            <li class="list-group-item">Part 3</li>
        </ul>
        <div class="card-body">
            <a href="#" class="card-link">Add More</a>
            <a href="#" class="card-link">Share</a>
        </div>
    </div>
</div>

Mix and Match Multiple Content Types within Card

Feel free to mix and match multiple content types to create the card layout you desire. The following example creates a fixed-width card with an image, text, list group, and hyperlinks.

<div class="m-4">
    <div class="card" style="width: 300px;">
        <img src="thumbnail.png" class="w-100 border-bottom" alt="Sample Image">
        <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">The content of the card is represented by the following sample text. You may always substitute your own text for it.</p>
        </div>
        <ul class="list-group list-group-flush">
            <li class="list-group-item">Part 1</li>
            <li class="list-group-item">Part 2</li>
            <li class="list-group-item">Part 3</li>
        </ul>
        <div class="card-body">
            <a href="#" class="card-link">Card link</a>
            <a href="#" class="card-link">Another link</a>
        </div>
    </div>
</div>

Adding Navigation to Cards

Additionally, you can add Bootstrap's nav components, such as tabs and pills, to the card header.

To add tabs navigation, simply place the tabs markup inside the card header and the tabs content inside the card body. You will also need to use the additional class .card-header-tabs on the .nav element along with the class .nav-tabs for proper alignment.

The example below illustrates an elegant tabbed navigation.

<div class="m-4">
    <div class="card text-center">
        <div class="card-header">
            <ul class="nav nav-tabs card-header-tabs" id="myTab">
                <li class="nav-item">
                    <a href="#home" class="nav-link active" data-bs-toggle="tab">Home</a>
                </li>
            </ul>
        </div>
        <div class="card-body">
            <div class="tab-content">
                <div class="tab-pane fade show active" id="home">
                    <h5 class="card-title">Home tab content</h5>
                    <p class="card-text">The contents of the tabs is represented by the following sample text. Anytime you want, substitute your own text.</p>
                    <a href="#" class="btn btn-primary">Go somewhere</a>
                </div>
            </div>
        </div>
    </div>
</div>

You can also incorporate pills nav into the card by adding the additional class .card-header-pills along with the class .nav-pills on the .nav element, as demonstrated below:

<div class="m-4">
    <div class="card text-center">
        <div class="card-header">
            <ul class="nav nav-pills card-header-pills">
                <li class="nav-item">
                    <a href="#home" class="nav-link active" data-bs-toggle="tab">Home</a>
                </li>
                <li class="nav-item">
                    <a href="#profile" class="nav-link" data-bs-toggle="tab">Profile</a>
                </li>
            </ul>
        </div>
        <div class="card-body">
            <div class="tab-content">
                <div class="tab-pane fade show active" id="Div1">
                    <h5 class="card-title">Home tab content</h5>
                    <p class="card-text">The contents of the tabs is represented by the following sample text. Anytime you want, substitute your own text.</p>
                    <a href="#" class="btn btn-primary">Go somewhere</a>
                </div>
            </div>
        </div>
    </div>
</div>

Customizing the Card Styles

There are various options available for customizing the appearance of a card's backgrounds, borders, and colors.

Customizing Background and Color

You can easily change the card's appearance using background and color utility classes. The following example illustrates how it works:

<div class="card text-white bg-primary mb-4">
    <div class="card-body">
        <h5 class="card-title">First card title</h5>
        <p class="card-text">To fill up the content of the cards, some fake text. It is always replaceable.</p>
    </div>
</div>

Customizing Border and Color

Similarly, you can customize the border and text color of any card using the text and border utility classes. Simply apply these classes to the .card or its child elements, as shown here:

<div class="card border-primary mb-4">
    <div class="card-body text-primary">
        <h5 class="card-title">First card title</h5>
        <p class="card-text">To fill up the card's content, some fictitious words. It can always be changed.</p>
    </div>
</div>

Card Layout Options

Aside from styling options, Bootstrap offers a few layout options for arranging a series of cards. However, these layouts are not yet responsive.

Creating the Card Groups

Card groups allow you to display cards as a single, attached element with equal-width and equal-height columns. However, on extra small devices (viewport width < 576px), cards inside a card group become horizontally stacked. Let's explore an example to see how it works:

<div class="m-4">
    <div class="card-group">
        <div class="card">
            <img src="thumbnail.png" class="card-img-top" alt="...">
            <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">To fill up the content of the cards, some fake text. It is always replaceable.</p>
            </div>
            <div class="card-footer">
                <small class="text-muted">Last updated 5 mins ago</small>
            </div>
        </div>

Creating the Card Grids

You can control the number of grid columns (wrapped around your cards) per row using the Bootstrap grid system and its .row-cols-* classes. For instance, you can use .row-cols-1 to display one card per row or .row-cols-md-2 to show two cards per row from the medium breakpoint up (viewport width ≥ 768px).

<div class="m-4">
    <div class="row row-cols-1 row-cols-md-2 g-4">
        <div class="col">
            <div class="card">
                <img src="thumbnail.png" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">Card title</h5>
                    <p class="card-text">To fill up the content of the cards, some fake text. It is always replaceable.</p>
                </div>
                <div class="card-footer">
                    <small class="text-muted">Last updated 5 mins ago</small>
                </div>
            </div>
        </div>   
      

Creating Horizontal Cards

To create horizontal cards where image and text content are placed side-by-side, you can use a combination of grid and utility classes, as depicted in the following example:

<div class="m-4">
    <div class="card" style="max-width: 500px;">
        <div class="row g-0">
            <div class="col-sm-5" style="background: #868e96;">
                <img src="sample.png" class="card-img-top h-100" alt="...">
            </div>
            <div class="col-sm-7">
                <div class="card-body">
                    <h5 class="card-title">Alice Liddel</h5>
                    <p class="card-text">London-based independent web designer and developer named Alice. She is skilled in JavaScript, HTML5, CSS3, and Bootstrap, among other things.</p>
                    <a href="#" class="btn btn-primary stretched-link">View Profile</a>
                </div>
            </div>
        </div>
    </div>
</div>

Card Image Overlays

Furthermore, you can turn an image into a card background and place the card's text on top of it using the class .card-img-overlay instead of .card-body. Depending on the image, additional styles may be required for better adjustments:

<div class="m-4">
    <div class="card text-white" style="width: 350px;">
        <img src="sample.png" class="card-img-top" alt="...">
        <div class="card-img-overlay">
            <h5 class="card-title">Alice Liddel</h5>
            <p class="card-text">London-based independent web designer and developer named Alice. She is skilled in JavaScript, HTML5, CSS3, and Bootstrap, among other things.</p>
            <a href="#" class="btn btn-primary stretched-link">View Profile</a>
        </div>
    </div>
</div>

Note: It's essential to ensure that the card content does not exceed the height of the image. If the content is larger, it will be displayed outside the image.


Text Alignment inside Card

To change the text alignment of a card, you can use the text alignment utility classes. For example, the class .text-center and .text-end can be used to align the card's text content to the center and right end, respectively.

<div class="m-4">
    <div class="row row-cols-1 row-cols-md-3 g-3">
        <div class="col">
            <!-- Card with default left text alignment -->
            <div class="card">
                <div class="card-body">
                    <h5 class="card-title">Card title</h5>
                    <p class="card-text">To fill up the content of the card, some fake text. It is always replaceable.</p>
                    <a href="#" class="btn btn-primary">Know more</a>
                </div>
            </div>
        </div>

Specifying Card Size

Cards have no fixed width; they are 100% wide by default. However, you can adjust the width as needed using custom CSS, grid classes, or sizing utility classes.

The example below demonstrates this:

<div class="m-4">
    <div class="container-fluid">
        <!-- Card sizing using grid markup -->
        <div class="row mb-4">
            <div class="col-sm-6">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">Card title</h5>
                        <p class="card-text">To fill up the content of the card, some fake text. It is always replaceable.</p>
                        <a href="#" class="btn btn-primary">Know more</a>
                    </div>
                </div>
            </div>

Card with Stretched Link

To make the entire card clickable, you can add the class .stretched-link to a link inside the card. Multiple links are not recommended with stretched links.

The following example shows how it works:

<div class="m-4">
    <div class="card" style="width: 300px;">
        <img src="sample.png" class="card-img-top" alt="...">
        <div class="card-body text-center">
            <h5 class="card-title">Alice Liddel</h5>
            <p class="card-text">London-based independent web designer and developer named Alice. She is skilled in JavaScript, HTML5, CSS3, and Bootstrap, among other things.</p>
            <a href="#" class="btn btn-primary stretched-link">View Profile</a>
        </div>
    </div>
</div>

FAQ

What is a Bootstrap Card?

A Bootstrap Card is a flexible and lightweight content container within the Bootstrap framework. It's a versatile component used to organize and display various types of content such as images, text, links, and more. Cards are designed to be visually appealing and responsive, adapting to different screen sizes and devices.

How do you create a basic Bootstrap Card?

To create a basic Bootstrap Card, you can use the following HTML structure:

<div class="card">
  <img src="image.jpg" class="card-img-top" alt="Image">
  <div class="card-body">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">This is a basic card with some sample content.</p>
    <a href="#" class="btn btn-primary">Learn More</a>
  </div>
</div>

In this example, the card class creates the card container, the card-img-top class is used for the image at the top, and the card-body class contains the title, text, and button elements.

How can you customize the appearance of a Bootstrap Card?

Bootstrap provides various classes that you can use to customize the appearance of a card. Some common classes include:

  • bg-*: To set the background color of the card, replacing * with a color name or contextual class like primary, success, etc.
  • text-*: To change the text color, replacing * with a color name or contextual class.
  • border-*: To add borders, replacing * with a color name or contextual class.
<div class="card bg-primary text-white border-0">
  <!-- Card content here -->
</div>

Can you include headers, footers, and other elements in a Bootstrap Card?

Yes, you can include headers, footers, and other elements in a Bootstrap Card. For instance, you can add a card header using the card-header class and a card footer using the card-footer class. These sections can contain additional content like titles, icons, buttons, etc.

<div class="card">
  <div class="card-header">
    Card Header
  </div>
  <div class="card-body">
    <!-- Card content here -->
  </div>
  <div class="card-footer">
    Card Footer
  </div>
</div>

How can you create a card layout with multiple cards in a row?

You can use Bootstrap's grid system to create a card layout with multiple cards in a row. For instance, to create a row of three cards, you can use the following structure:

<div class="row">
  <div class="col-md-4">
    <!-- Card 1 content here -->
  </div>
  <div class="col-md-4">
    <!-- Card 2 content here -->
  </div>
  <div class="col-md-4">
    <!-- Card 3 content here -->
  </div>
</div>

How can you make the cards responsive for different screen sizes?

Bootstrap Cards are responsive by default. The grid system ensures that cards adjust their width and layout based on the screen size. To achieve this responsiveness, you should place your cards within the appropriate grid columns using classes like col-sm-*, col-md-*, col-lg-*, etc., to control the number of columns the cards should span across for different screen sizes.

How can you create a card with different styles, such as horizontal cards or card groups?

Bootstrap offers different card styles, including horizontal cards and card groups. To create a horizontal card, you can use the flex-row class to align the card content horizontally:

<div class="card flex-row">
  <img src="image.jpg" class="card-img-left" alt="Image">
  <div class="card-body">
    <h5 class="card-title">Horizontal Card</h5>
    <p class="card-text">This is a horizontal card layout.</p>
  </div>
</div>

For card groups, you can enclose multiple cards within a card-group or card-deck container:

<div class="card-group">
  <div class="card">
    <!-- Card 1 content here -->
  </div>
  <div class="card">
    <!-- Card 2 content here -->
  </div>
  <!-- More cards -->
</div>

How can you control the width of a Bootstrap Card?

You can control the width of a Bootstrap Card by adjusting the width of the containing column. For instance, if you want a card to occupy half the width of its column, you can use the col-md-6 class:

<div class="col-md-6">
  <div class="card">
    <!-- Card content here -->
  </div>
</div>

How can you use card overlays for additional content, such as text or buttons on images?

Card overlays can be used to display additional content, such as text or buttons, on top of card images. You can achieve this by using the card-img-overlay class:

<div class="card">
  <img src="image.jpg" class="card-img" alt="Image">
  <div class="card-img-overlay">
    <h5 class="card-title">Image Overlay</h5>
    <p class="card-text">Text over the image.</p>
    <a href="#" class="btn btn-primary">Button</a>
  </div>
</div>

How can you add icons or badges to a Bootstrap Card?

You can add icons using Bootstrap's icon classes (e.g., bi bi-heart) and badges using the badge class. Here's an example of adding an icon and a badge to a card:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Card with Icon and Badge</h5>
    <p class="card-text">This card has an icon and a badge.</p>
    <a href="#" class="btn btn-primary">Learn More</a>
  </div>
  <i class="bi bi-star-fill card-icon"></i>
  <span class="badge bg-secondary">New</span>
</div>

In this example, the card-icon class is used to style the icon.

How can you use card decks and card columns to arrange multiple cards?

Card decks and card columns are useful for arranging multiple cards in different layouts. A card deck ensures equal height for all cards, while card columns allow for responsive columns. Here's how to use them:

For card decks:

<div class="card-deck">
  <div class="card">
    <!-- Card 1 content here -->
  </div>
  <div class="card">
    <!-- Card 2 content here -->
  </div>
  <!-- More cards -->
</div>

For card columns:

<div class="card-columns">
  <div class="card">
    <!-- Card 1 content here -->
  </div>
  <div class="card">
    <!-- Card 2 content here -->
  </div>
  <!-- More cards -->
</div>

How can you add hover effects or animations to Bootstrap Cards?

You can add hover effects and animations using Bootstrap's utility classes or CSS. For example, to add a subtle zoom effect on hover:

<div class="card card-zoom">
  <!-- Card content here -->
</div>
.card-zoom:hover {
  transform: scale(1.05);
  transition: transform 0.3s ease;
}

You can customize the CSS properties to achieve the desired effect.

How can you make a card's height adjust to its content?

By default, Bootstrap Cards adjust their height based on their content. If you want to ensure that the card height is the same for multiple cards in a row, you can use the align-items-stretch class on the parent container to make them equal in height.

Can you include forms or input elements inside a Bootstrap Card?

Absolutely! You can include forms, input elements, and other interactive components within a Bootstrap Card. Here's an example of a card containing a form:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Contact Us</h5>
    <form>
      <!-- Form fields here -->
      <button type="submit" class="btn btn-primary">Submit</button>
    </form>
  </div>
</div>

How can you create card layouts with equal heights regardless of content?

If you want to ensure that cards have equal heights within a row, you can use the align-items-stretch class on the parent container:

<div class="row align-items-stretch">
  <div class="col-md-4">
    <!-- Card 1 content here -->
  </div>
  <div class="col-md-4">
    <!-- Card 2 content here -->
  </div>
  <div class="col-md-4">
    <!-- Card 3 content here -->
  </div>
</div>

This ensures that all cards within the row have the same height, regardless of the content.

Can you use Bootstrap Cards for displaying images in a gallery format?

Yes, you can use Bootstrap Cards to create an image gallery. Each card can represent an image, and you can use a grid layout to organize them. For example:

<div class="row">
  <div class="col-md-4">
    <div class="card">
      <img src="image1.jpg" class="card-img-top" alt="Image 1">
    </div>
  </div>
  <div class="col-md-4">
    <div class="card">
      <img src="image2.jpg" class="card-img-top" alt="Image 2">
    </div>
  </div>
  <!-- More cards for other images -->
</div>

Is it possible to create customized content using HTML within a Bootstrap Card?

Yes, you can create customized content using HTML within a Bootstrap Card. You have full control over the card's content, allowing you to combine various elements:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Custom Card</h5>
    <p class="card-text">This card contains a <span class="badge bg-info">custom badge</span> and an <i class="bi bi-star"></i> icon.</p>
    <a href="#" class="btn btn-secondary">Learn More</a>
  </div>
</div>

In this example, we're using Bootstrap's badge class and an icon from Bootstrap Icons.

How can you create card layouts with images and captions?

To create card layouts with images and captions, you can use the card-img class for the image and include the caption within the card-img-overlay class. Here's an example:

<div class="card">
  <img src="image.jpg" class="card-img" alt="Image">
  <div class="card-img-overlay">
    <h5 class="card-title">Image Caption</h5>
    <p class="card-text">This is a caption for the image.</p>
  </div>
</div>

How can you incorporate media content like videos or audio within a Bootstrap Card?

You can embed media content like videos or audio within a Bootstrap Card using standard HTML video and audio tags. Here's an example of embedding a video:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Video Card</h5>
    <p class="card-text">Check out this video:</p>
    <video controls>
      <source src="video.mp4" type="video/mp4">
      Your browser does not support the video tag.
    </video>
  </div>
</div>

How can you use badges and labels within a Bootstrap Card?

You can incorporate badges and labels within a Bootstrap Card to highlight additional information. Use the badge class for badges and customize their style using contextual classes:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Product Name</h5>
    <p class="card-text">This product has a <span class="badge badge-info">New</span> label.</p>
  </div>
</div>

How can you include lists and other structured content within a Bootstrap Card?

You can easily include lists and structured content within a Bootstrap Card. Here's an example with an unordered list:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">List Card</h5>
    <ul class="list-group">
      <li class="list-group-item">Item 1</li>
      <li class="list-group-item">Item 2</li>
      <li class="list-group-item">Item 3</li>
    </ul>
  </div>
</div>

How can you create cards with varying background colors?

You can customize the background color of cards using Bootstrap's contextual classes, such as bg-primary, bg-success, etc. Here's an example:

<div class="card bg-primary text-white">
  <div class="card-body">
    <h5 class="card-title">Colored Card</h5>
    <p class="card-text">This card has a primary background color.</p>
  </div>
</div>

How can you create cards with custom content alignment and layout?

You can use Bootstrap's utility classes to adjust content alignment and layout within a card. For example, to center-align content:

<div class="card">
  <div class="card-body text-center">
    <h5 class="card-title">Centered Content</h5>
    <p class="card-text">This content is centered within the card body.</p>
  </div>
</div>

What is a "Body Only" card in Bootstrap?

A "Body Only" card in Bootstrap refers to a card component that contains only the main content body without any additional headers, footers, or images. It's a minimalist way to present information in a clean and straightforward manner.

How can you create a "Body Only" card in Bootstrap?

To create a "Body Only" card, you can omit the card header, footer, and image elements, focusing solely on the card's content body:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">This is a "Body Only" card without any extra elements.</p>
    <a href="#" class="btn btn-primary">Learn More</a>
  </div>
</div>

In this example, the card-body class is used to enclose the main content of the card.

Can you customize the appearance of a "Body Only" card?

Absolutely. You can customize the appearance of a "Body Only" card using various Bootstrap utility classes. For instance, you can apply background colors, text colors, and border styles to achieve the desired look.

<div class="card bg-success text-white border-0">
  <div class="card-body">
    <h5 class="card-title">Styled "Body Only" Card</h5>
    <p class="card-text">This card has a green background and white text.</p>
  </div>
</div>

How can you create "Body Only" cards that expand to show more content?

You can create "Body Only" cards that expand to show more content using Bootstrap's Collapse component. Here's an example:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Expandable Card</h5>
    <p class="card-text">Click the button to see more content:</p>
    <div class="collapse" id="expandableContent">
      <p>Additional content revealed here.</p>
    </div>
    <a href="#" class="btn btn-primary" data-toggle="collapse" data-target="#expandableContent">Toggle Content</a>
  </div>
</div>

How can you make the entire card clickable using a link?

To make the entire card clickable using a link, you can wrap the entire card content within an anchor (<a>) tag:

<a href="#" class="card-link">
  <div class="card">
    <div class="card-body">
      <h5 class="card-title">Clickable Card</h5>
      <p class="card-text">This entire card is a clickable link.</p>
    </div>
  </div>
</a>

How can you include icons within headers and footers of a Bootstrap Card?

You can include icons within headers and footers of a Bootstrap Card using Bootstrap's icon classes. Here's an example of adding icons to the header and footer:

<div class="card">
  <div class="card-header">
    <h5 class="card-title">Icon Header</h5>
    <p class="card-subtitle">
      <i class="bi bi-calendar"></i> Date: August 30, 2023
    </p>
  </div>
  <div class="card-body">
    <p class="card-text">This is the card content.</p>
  </div>
  <div class="card-footer">
    <a href="#"><i class="bi bi-link"></i> Visit Website</a>
  </div>
</div>

In this example, the <i> elements with the bi bi-calendar and bi bi-link classes add a calendar and link icon, respectively.

How can you make the footer of a Bootstrap Card stick to the bottom of the card, regardless of content length?

You can make the footer of a Bootstrap Card stick to the bottom of the card by utilizing the flexbox utility classes. Here's an example:

<div class="card d-flex flex-column">
  <div class="card-body">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">This is the card content.</p>
  </div>
  <div class="mt-auto card-footer">
    Sticky Footer
  </div>
</div>

In this example, the d-flex class makes the card a flex container, and mt-auto pushes the footer to the bottom of the container.

How can you customize the appearance of List Group items within a Bootstrap Card?

You can customize the appearance of List Group items within a Bootstrap Card using various Bootstrap utility classes. For example, you can use list-group-item-primary, list-group-item-success, etc., to apply different colors:

<ul class="list-group">
  <li class="list-group-item list-group-item-primary">Primary Item</li>
  <li class="list-group-item list-group-item-success">Success Item</li>
  <li class="list-group-item list-group-item-danger">Danger Item</li>
</ul>

How can you make List Group items within a Bootstrap Card interactive?

You can make List Group items within a Bootstrap Card interactive by adding appropriate CSS and JavaScript for handling events like clicks. For example:

<ul class="list-group">
  <li class="list-group-item list-group-item-action" onclick="handleItemClick(1)">Item 1</li>
  <li class="list-group-item list-group-item-action" onclick="handleItemClick(2)">Item 2</li>
</ul>
function handleItemClick(itemId) {
  alert('Clicked on Item ' + itemId);
}

How can you create a horizontally-oriented List Group within a Bootstrap Card?

To create a horizontally-oriented List Group within a Bootstrap Card, you can use the list-group-horizontal class. Here's an example:

<ul class="list-group list-group-horizontal">
  <li class="list-group-item">Item 1</li>
  <li class="list-group-item">Item 2</li>
  <li class="list-group-item">Item 3</li>
</ul>

Can you use List Group items as navigation links within a Bootstrap Card?

Yes, you can use List Group items as navigation links within a Bootstrap Card. By adding href attributes to the List Group items, you can create navigation links:

<ul class="list-group">
  <a href="#section1" class="list-group-item list-group-item-action">Section 1</a>
  <a href="#section2" class="list-group-item list-group-item-action">Section 2</a>
  <a href="#section3" class="list-group-item list-group-item-action">Section 3</a>
</ul>

How can you create a List Group with flush (borderless) styling within a Bootstrap Card?

To create a List Group with flush (borderless) styling within a Bootstrap Card, you can add the list-group-flush class to the list-group element:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Flush List Group Card</h5>
    <ul class="list-group list-group-flush">
      <li class="list-group-item">Item 1</li>
      <li class="list-group-item">Item 2</li>
      <li class="list-group-item">Item 3</li>
    </ul>
  </div>
</div>

How can you create a complex card layout with a List Group and additional content?

You can create a complex card layout with a List Group and additional content by combining the List Group with other card components. Here's an example:

<div class="card">
  <div class="card-body">
    <h5 class="card-title">Complex Card Layout</h5>
    <p class="card-text">This card includes a List Group and additional content.</p>
    <ul class="list-group">
      <li class="list-group-item">Item 1</li>
      <li class="list-group-item">Item 2</li>
      <li class="list-group-item">Item 3</li>
    </ul>
  </div>
  <div class="card-footer">
    Card Footer
  </div>
</div>

Can you add contextual styling to List Group items within a Bootstrap Card?

Yes, you can add contextual styling to List Group items within a Bootstrap Card using Bootstrap's contextual classes. These classes allow you to apply different background colors to the List Group items based on their purpose or status:

<ul class="list-group">
  <li class="list-group-item list-group-item-primary">Primary Item</li>
  <li class="list-group-item list-group-item-success">Success Item</li>
  <li class="list-group-item list-group-item-danger">Danger Item</li>
</ul>

Can you mix horizontal and vertical content alignment within a Bootstrap Card?

Yes, you can mix horizontal and vertical content alignment within a Bootstrap Card using utility classes like d-flex, justify-content-between, and align-items-center:

<div class="card">
  <div class="card-body d-flex justify-content-between align-items-center">
    <h5 class="card-title">Aligned Card</h5>
    <span class="badge badge-pill badge-success">New</span>
  </div>
</div>

How can you open navigation links in a new tab when clicked?

To open navigation links in a new tab when clicked, you can use the target="_blank" attribute on the anchor (<a>) tag:

<a href="page.html" target="_blank" class="card-link">
  <div class="card">
    <div class="card-body">
      <h5 class="card-title">Open Link in New Tab</h5>
      <p class="card-text">This card's link will open in a new tab.</p>
    </div>
  </div>
</a>

How can you create navigation cards that act as tabs to switch between content sections?

You can create navigation cards that act as tabs using the Bootstrap Tabs component. Each tab can contain a card with its own content. Here's an example:

<div class="card">
  <div class="card-header">
    <ul class="nav nav-tabs card-header-tabs">
      <li class="nav-item">
        <a class="nav-link active" data-toggle="tab" href="#section1">Section 1</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" data-toggle="tab" href="#section2">Section 2</a>
      </li>
    </ul>
  </div>
  <div class="card-body tab-content">
    <div class="tab-pane fade show active" id="section1">
      <h5 class="card-title">Section 1 Content</h5>
      <p class="card-text">This is the content of section 1.</p>
    </div>
    <div class="tab-pane fade" id="section2">
      <h5 class="card-title">Section 2 Content</h5>
      <p class="card-text">This is the content of section 2.</p>
    </div>
  </div>
</div>

How can I change the font style and size of text within Bootstrap cards?

To modify the font style and size of text within Bootstrap cards, you can target the relevant card elements using CSS. Here's how:

.custom-card {
  font-family: "Arial", sans-serif; /* Change font family */
}

.card-title {
  font-size: 24px; /* Change title font size */
}

.card-text {
  font-size: 16px; /* Change content font size */
}

In this example, the .custom-card class sets the font family for the entire card. The .card-title and .card-text classes control the font sizes of the card's title and content, respectively.

How can I create a hover effect that changes the background color of the Bootstrap card?

You can achieve a hover effect that changes the background color of a Bootstrap card using CSS. Here's an example:

.custom-card:hover {
  background-color: #f0f0f0; /* Change background color on hover */
}

In this case, the .custom-card class changes the background color of the card when it's hovered over by the user.

Can I change the padding and margin of Bootstrap cards to adjust spacing?

Yes, you can adjust the padding and margin of Bootstrap cards to control spacing around and within the card. Here's how:

.custom-card {
  padding: 20px; /* Adjust internal spacing */
  margin: 10px; /* Adjust spacing around the card */
}

The padding property controls the internal spacing within the card's content, and the margin property adjusts the spacing around the entire card.

How can I create a card with a transparent background?

To create a card with a transparent background, you can override the default card background color with a transparent value. Here's how:

.transparent-card {
  background-color: transparent; /* Set background color to transparent */
  border: 1px solid #ccc; /* Add a border for visibility */
}

In this example, the .transparent-card class sets the card's background color to transparent. You can add a border for visibility or adjust other styling as needed.

How can I center-align text within a Bootstrap card's content?

To center-align text within a Bootstrap card's content, you can use CSS to adjust the text alignment. Here's an example:

.center-aligned-card {
  text-align: center; /* Center-align text within the card */
}

Apply the .center-aligned-card class to your card's HTML div element.

How can I create a Bootstrap card with a colored border and background?

You can create a Bootstrap card with a colored border and background by combining background color and border color properties. Here's an example using custom CSS:

.custom-card {
  background-color: #F5B041; /* Background color */
  border: 2px solid #E74C3C; /* Border color */
}

In this example, the .custom-card class sets the background color to #F5B041 and the border color to #E74C3C.

How can I apply different border radius to Bootstrap cards to create rounded corners?

Applying different border radius to Bootstrap cards can be done using CSS. You can control the corner roundness using the border-radius property. Here's an example:

.rounded-card {
  border-radius: 10px; /* Apply rounded corners */
}

In this case, the .rounded-card class applies a border radius of 10px to all corners of the card. You can also target specific corners using the border-radius property's individual values, like border-top-left-radius, border-top-right-radius, etc.

How can I create a card group with cards displayed as a vertical list?

You can create a card group with cards displayed as a vertical list using the .card-group class. Cards within a .card-group stack vertically.

<div class="card-group">
  <div class="card">
    <!-- Card content -->
  </div>
  <div class="card">
    <!-- Card content -->
  </div>
  <div class="card">
    <!-- Card content -->
  </div>
</div>

How can I create a responsive grid of cards that adapt to different screen sizes?

Bootstrap's grid system allows you to create responsive card grids by using different column classes for various screen sizes. Here's an example:

<div class="row">
  <div class="col-sm-6 col-md-4 col-lg-3">
    <div class="card">
      <!-- Card content -->
    </div>
  </div>
  <div class="col-sm-6 col-md-4 col-lg-3">
    <div class="card">
      <!-- Card content -->
    </div>
  </div>
  <!-- Add more columns as needed -->
</div>

2 columns on small screens, 3 columns on medium screens, and 4 columns on large screens.

What are horizontal cards in Bootstrap?

Horizontal cards in Bootstrap are cards that are oriented horizontally instead of the traditional vertical layout. They are often used when you want to display content side by side within a card, such as an image on one side and text on the other.

How can I create a basic horizontal card in Bootstrap?

To create a basic horizontal card in Bootstrap, you can use the .flex-row class along with utility classes for alignment. Here's an example:

<div class="card flex-row">
  <img src="image.jpg" class="card-img-left" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">Card content goes here.</p>
  </div>
</div>

In this example, the .flex-row class creates a horizontal layout, and the .card-img-left class positions the image on the left side.

How can I create a horizontal card with a card header and footer?

You can create a horizontal card with a card header and footer by placing the header and footer elements within the card's body. Here's an example:

<div class="card flex-row">
  <img src="image.jpg" class="card-img-left" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">Card content goes here.</p>
    <div class="card-header">
      Card Header
    </div>
    <div class="card-footer">
      Card Footer
    </div>
  </div>
</div>

In this example, the card header and footer are placed inside the card's body, and the .flex-row class creates the horizontal layout.

How can I create a horizontal card with an image on the right side?

To create a horizontal card with an image on the right side, you can use the .flex-row-reverse class. Here's an example:

<div class="card flex-row-reverse">
  <div class="card-body">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">Card content goes here.</p>
  </div>
  <img src="image.jpg" class="card-img-right" alt="...">
</div>

In this example, the .flex-row-reverse class creates a horizontal layout with the image on the right side.

How can I create a horizontal card with a custom width for the image and content?

To create a horizontal card with a custom width for the image and content, you can use utility classes for sizing. Here's an example:

<div class="card flex-row">
  <img src="image.jpg" class="card-img-left img-fluid" style="width: 200px;" alt="...">
  <div class="card-body" style="width: calc(100% - 200px);">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">Card content goes here.</p>
  </div>
</div>

In this example, the .img-fluid class ensures the image is responsive, and custom widths are applied to both the image and the content.

How can I align the content vertically within a horizontal card?

You can align the content vertically within a horizontal card using flex utilities. Here's an example:

<div class="card flex-row align-items-center">
  <img src="image.jpg" class="card-img-left" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">Card content goes here.</p>
  </div>
</div>

In this example, the .align-items-center class vertically centers the content within the card.

How can I create a horizontal card with a button on the right side?

You can create a horizontal card with a button on the right side by using flex utilities for alignment. Here's an example:

<div class="card flex-row">
  <img src="image.jpg" class="card-img-left" alt="...">
  <div class="card-body d-flex flex-column justify-content-between">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">Card content goes here.</p>
    <button class="btn btn-primary align-self-end">Button</button>
  </div>
</div>

In this example, the .d-flex, .flex-column, and .justify-content-between classes create a vertical layout with the button aligned to the bottom.

How can I create a responsive horizontal card grid?

To create a responsive horizontal card grid, you can use the grid system along with horizontal cards. Here's an example:

<div class="row">
  <div class="col-md-6">
    <div class="card flex-md-row">
      <!-- Card content -->
    </div>
  </div>
  <div class="col-md-6">
    <div class="card flex-md-row">
      <!-- Card content -->
    </div>
  </div>
</div>

In this example, the col-md-6 class creates a responsive grid, and the flex-md-row class makes the cards horizontal on medium screens and larger.

How can I create a horizontal card with different content alignment for each side?

You can create a horizontal card with different content alignment for each side by using utility classes. Here's an example:

<div class="card flex-row">
  <img src="image.jpg" class="card-img-left align-self-center" alt="...">
  <div class="card-body text-right">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">Card content goes here.</p>
  </div>
</div>

In this example, the align-self-center class centers the image vertically, and the text-right class aligns the content on the right side.

How can I create a horizontal card with different content on different screen sizes?

You can use Bootstrap's responsive classes to display different content on different screen sizes. Here's an example:

<div class="card flex-row">
  <img src="image.jpg" class="card-img-left" alt="...">
  <div class="card-body">
    <h5 class="card-title d-none d-sm-block">Card Title (Desktop)</h5>
    <h5 class="card-title d-block d-sm-none">Card Title (Mobile)</h5>
    <p class="card-text">Card content goes here.</p>
  </div>
</div>

In this example, the .d-none and .d-sm-block classes hide the desktop title on small screens and show the mobile title, while the .d-block and .d-sm-none classes do the opposite.

How can I make the overlay content in a card image overlay vertically centered?

You can make the overlay content in a card image overlay vertically centered by using flex utilities for alignment. Here's an example:

<div class="card">
  <img src="image.jpg" class="card-img" alt="...">
  <div class="card-img-overlay d-flex align-items-center justify-content-center">
    <h5 class="card-title">Overlay Title</h5>
    <p class="card-text">Overlay content goes here.</p>
  </div>
</div>

In this example, the .d-flex, .align-items-center, and .justify-content-center classes vertically and horizontally center the overlay content.

How can I make the image overlay text have a transparent background?

You can make the image overlay text have a transparent background by using custom CSS to adjust the background color and opacity. Here's an example:

<style>
  .transparent-overlay {
    background-color: rgba(255, 255, 255, 0.5);
    padding: 20px;
  }
</style>

<div class="card">
  <img src="image.jpg" class="card-img" alt="...">
  <div class="card-img-overlay transparent-overlay">
    <h5 class="card-title">Overlay Title</h5>
    <p class="card-text">Overlay content goes here.</p>
  </div>
</div>

In this example, the .transparent-overlay class sets a semi-transparent white background for the overlay text.

Can I create a card image overlay with a video instead of an image?

Yes, you can create a card image overlay with a video by embedding the video within the card and applying the overlay to it. Here's an example:

<div class="card">
  <div class="embed-responsive embed-responsive-16by9">
    <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/VIDEO_ID" allowfullscreen></iframe>
  </div>
  <div class="card-img-overlay">
    <h5 class="card-title">Video Overlay</h5>
    <p class="card-text">Overlay content goes here.</p>
  </div>
</div>

In this example, the video is embedded using the .embed-responsive class, and the overlay is added as usual.

How can I apply different text alignments to different parts of the card body?

You can apply different text alignments to different parts of the card body by using separate classes for each section. Here's an example:

<div class="card">
  <div class="card-body">
    <h5 class="card-title text-center">Centered Title</h5>
    <p class="card-text text-right">Right-aligned content.</p>
    <p class="card-text text-left">Left-aligned content.</p>
  </div>
</div>

In this example, each element inside the card body has its own text alignment class.

How can I center align the card header and footer text?

To center align the card header and footer text, you can use the .card-header and .card-footer classes along with the .text-center class. Here's an example:

<div class="card">
  <div class="card-header text-center">
    Centered Header
  </div>
  <div class="card-body">
    <h5 class="card-title">Card Title</h5>
    <p class="card-text">Card content goes here.</p>
  </div>
  <div class="card-footer text-center">
    Centered Footer
  </div>
</div>

In this example, the .text-center class aligns the text inside both the header and footer to the center.

How can I center align the text vertically and horizontally within a card body?

You can center align the text both vertically and horizontally within a card body by using the .d-flex, .align-items-center, and .justify-content-center classes. Here's an example:

<div class="card">
  <div class="card-body d-flex align-items-center justify-content-center">
    <h5 class="card-title">Centered Text</h5>
    <p class="card-text">Content is centered both vertically and horizontally.</p>
  </div>
</div>

In this example, the .d-flex class creates a flex container, and both .align-items-center and .justify-content-center classes center the content both vertically and horizontally.


Conclusion

Bootstrap Cards epitomize a versatile and powerful component for web development, characterized by a flexible grid system and responsive design. The grid-based approach enables the creation of visually appealing and responsive cards, ensuring a seamless and adaptable layout across devices.

From Panel Components and Information Tiles to Boxed Elements and Grid-Based Cards, the diverse range of card types allows for creativity and customization. These cards serve as effective Informational Tiles and Grid-Style Display Panels, providing developers with options to present content in visually appealing ways.

The concept of Responsive Card Design further enhances user experiences, providing a dynamic and user-friendly interface for presenting content. The inclusion of Dynamic Information Panels, Customizable Boxed Layout, and Panelized Information Blocks empowers developers to craft engaging and personalized displays, catering to specific design needs.

The versatility of Sectioned Card Elements introduces a higher level of customization, allowing developers to create header/footer content, titled blocks, and linked information panels. The integration of Aligned Text Cards, Horizontal Content Blocks, and Side-by-Side Card Design provides precise control over text positioning, facilitating the creation of stylish and flexible horizontal layouts.

Whether through Image-Focused Data Tiles or Link-Integrated Cards, Bootstrap Cards offer a comprehensive toolkit for presenting diverse content types. The flexibility and adaptability of cards extend to customizable sections, dynamic headers and footers, and a range of styling options, ensuring developers have the tools needed to create visually appealing and user-friendly web interfaces.

In essence, Bootstrap Cards emerge as an integral part of web design, offering a balance between flexibility and responsiveness, facilitating the creation of diverse and engaging content layouts.