Welcome to Bootstrap Cards

You've successfully navigated through creating buttons, forms, modals, and accordions with Bootstrap. Now, let's expand your toolkit even further by exploring Bootstrap Cards. Cards are versatile and elegant components used to display content in a structured format, making your web pages more visually appealing and easier to navigate.

What You'll Learn

In this lesson, you'll master the creation and customization of Bootstrap Cards. We'll focus on understanding how to structure a card, add images, text, and buttons to create a cohesive and attractive element. By the end of this lesson, you'll be able to design a card similar to this:

Here are the key parts of the above code snippet:

  1. Card Container (<div class="card">): This is the Bootstrap class used to create the main container for the card. The style="width: 18rem;" sets the width of the card.
  2. Card Image (<img class="card-img-top">): This Bootstrap class is used to display an image at the top of the card. The alt attribute provides alternative text for the image.
  3. Card Body (<div class="card-body">): This section uses the Bootstrap class card-body to contain the main content of the card, including:
    • Card Title (<h5 class="card-title">): This Bootstrap class is used to display the title of the card.
    • Card Text (<p class="card-text">): This Bootstrap class provides additional information or description.
    • Card Button (<a class="btn btn-primary">): This Bootstrap class adds a button to the card, typically used to link to more information.
Content Types

Bootstrap Cards offer a versatile range of content options, making it easy to create visually appealing and functional cards. Let's explore some examples:

  1. Images:

    This uses the card-img-top class to place an image at the top of the card, providing a visually engaging start.

  2. Text and Titles:

    Use the card-title and card-text classes to add a catchy title and descriptive text, giving context and information to your card.

  3. Links:

    The card-link class is used to include links for additional navigation or resources, making your card interactive.

  4. List Groups:

    Add a list group using the list-group and list-group-flush classes to organize information neatly within the card, perfect for lists and itemized content.

Sizing

Customizing the size of Bootstrap Cards allows you to tailor them to fit various layouts and design needs. Here are some ways to do this:

  1. Fixed Width:

    Specify a fixed width to create uniformity and ensure your cards maintain a consistent size.

  2. Using Utility Classes for Width:

    Besides w-50, other width utility classes include w-25 for 25%, w-75 for 75%, w-100 for 100%, and w-auto for automatic width based on content. These classes provide quick and easy ways to adjust element widths responsively.

  3. Using Grid for Width:

    Utilize the grid system to control the width dynamically, ensuring your cards fit seamlessly within your layout. Other grid column classes such as col-sm-4 for 33.33% and col-sm-12 for 100% are also available for responsive design.

These examples highlight the adaptability of Bootstrap Cards, enabling you to create cards that not only look great but also function well within your design.

Why It Matters

Understanding how to use Bootstrap Cards is essential for modern web development. Cards provide a flexible and extensible content container, combining various elements like images, text, and links in a uniform style. They are perfect for organizing information, whether you're showcasing products, blog posts, or user profiles.

By mastering cards, you'll be able to create more interactive and visually engaging web pages. This not only enhances user experience but also makes your content more accessible and attractive.

Are you excited to see the impact of Bootstrap Cards on your web pages? Let's dive into the practice section and get started!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal