Bootstrap 5: Side by Side Cards Layout

Bootstrap, the popular CSS framework, has always been a go-to for web developers seeking to create responsive and mobile-first websites. With the release of Bootstrap 5, the framework has introduced several new features and improvements, including a revamped card component. One of the standout features of Bootstrap 5 cards is their ability to display side by side, enhancing the user interface's visual appeal and organization.

Bootstrap cards side by side responsive - Coding Yaar
Bootstrap cards side by side responsive - Coding Yaar

In this article, we'll delve into the world of Bootstrap 5 cards and explore how to display them side by side. We'll cover the basics, dive into the code, and provide practical examples to help you master this essential skill.

Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5

Understanding Bootstrap 5 Cards

Before we jump into displaying cards side by side, let's briefly recap what Bootstrap 5 cards are and their basic usage. Cards are a flexible and extensible content container. They allow you to create self-contained units of content with a heading and body, optionally including other elements like links, buttons, and media.

Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5

In Bootstrap 5, cards are built with CSS flexbox and are fully responsive. They use the `.card` class, with various utility classes available for customization, such as `.card-title`, `.card-text`, and `.card-body`.

Basic Bootstrap 5 Card Structure

Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5
Bootstrap Tutorial | Bootstrap Notes | Bootstrap 5

Here's a basic example of a Bootstrap 5 card:

<div class="card" style="width: 18rem;">
  <img src="..." class="card-img-top" alt="...">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <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 btn-primary">Go somewhere</a>
  </div>
</div>

This code creates a card with an image at the top, a title, some text, and a button.

Displaying Cards Side by Side with Flexbox

Bootstrap Photo Gallery
Bootstrap Photo Gallery

To display Bootstrap 5 cards side by side, we'll use the power of CSS flexbox. Flexbox is a one-dimensional layout model that allows items to be placed in a row or column, with proper alignment and distribution. In our case, we'll use it to place cards in a row.

First, wrap your cards in a container with the `.d-flex` class, which applies `display: flex;` to its children. Then, add the `.flex-wrap` class to allow the flex items to wrap as needed:

<div class="d-flex flex-wrap">
  <div class="card mr-2 mb-2" style="width: 18rem;">
    ...
  </div>
  <div class="card mr-2 mb-2" style="width: 18rem;">
    ...
  </div>
</div>

The `mr-2` and `mb-2` classes add right and bottom margins to the cards, creating space between them. Adjust these values as needed to achieve the desired layout.

Flip Card Code | Bootstrap 5.3 snippet to build elements that flip to reveal hidden content
Flip Card Code | Bootstrap 5.3 snippet to build elements that flip to reveal hidden content

Responsive Card Layouts

Bootstrap 5 cards are fully responsive, meaning they adapt to different screen sizes. By default, cards will stack on top of each other on small screens and display side by side on larger screens. However, you can customize this behavior using responsive display utilities.

How to Create Bootstrap Navbar | Responsive Navbar Tutoria
How to Create Bootstrap Navbar | Responsive Navbar Tutoria
#CSS Animations Tips and Tricks
#CSS Animations Tips and Tricks
Sidebar Menu using HTML CSS
Sidebar Menu using HTML CSS
the contact form page for this website
the contact form page for this website
The Design and Morality of The Card Interface
The Design and Morality of The Card Interface
bootstrap 5 cards side by side
bootstrap 5 cards side by side
bootstrap 5 cards side by side
bootstrap 5 cards side by side
Advertising Archives
Advertising Archives
Day 8 — Learn Tailwind CSS
Day 8 — Learn Tailwind CSS
Post by @udemysaveoff · 1 image
Post by @udemysaveoff · 1 image
Complete Beginner CSS Master Notes
Complete Beginner CSS Master Notes

For example, to display cards side by side only on medium and larger screens, you can wrap them in a container with the `.d-none d-sm-flex` classes:

<div class="d-none d-sm-flex flex-wrap">
  <div class="card mr-2 mb-2" style="width: 18rem;">
    ...
  </div>
  <div class="card mr-2 mb-2" style="width: 18rem;">
    ...
  </div>
</div>

In this case, the cards will be hidden on small screens (xs) and displayed side by side on medium (sm) and larger screens.

Equal-Width Cards

To create equal-width cards, you can use the `.col` classes from Bootstrap's grid system. Wrap each card in a `.col` element with the desired number of columns. For example, to create three equal-width cards, use `.col-md-4`:

<div class="d-flex flex-wrap">
  <div class="col-md-4 mb-3">
    <div class="card">
      ...
    </div>
  </div>
  <div class="col-md-4 mb-3">
    <div class="card">
      ...
    </div>
  </div>
  <div class="col-md-4 mb-3">
    <div class="card">
      ...
    </div>
  </div>
</div>

This will create three equal-width cards that stack on top of each other on small screens and display side by side on medium and larger screens.

In conclusion, displaying Bootstrap 5 cards side by side is a powerful way to organize and present content on your website. By harnessing the power of CSS flexbox and Bootstrap's grid system, you can create responsive and engaging card layouts that adapt to various screen sizes. So go ahead, experiment with different layouts, and make your web pages shine with beautifully arranged Bootstrap 5 cards.