Home > Web Front-end > CSS Tutorial > How to Achieve Equal Card Heights in Bootstrap Card Columns?

How to Achieve Equal Card Heights in Bootstrap Card Columns?

Barbara Streisand
Release: 2024-11-25 11:30:18
Original
515 people have browsed it

How to Achieve Equal Card Heights in Bootstrap Card Columns?

Bootstrap Card Columns: Achieving Equal Card Height

In Bootstrap 4, the card-columns class allows for the creation of an aesthetically pleasing layout where multiple cards are arranged in columns with variable heights. However, this can lead to uneven card heights, which may not be desirable.

To achieve uniform card heights, Bootstrap provides two solutions:

Option 1: Setting Heights on row or column Elements

You can align card heights by setting the align-items-stretch utility class on either the row or column elements within which the cards are contained. This will stretch the cards vertically to fill the available space.

<div class="container">
  <div class="row">
    <div class="col-lg-4 d-flex align-items-stretch">
      <!--CARD HERE-->
    </div>
    <div class="col-lg-4 d-flex align-items-stretch">
      <!--CARD HERE-->
    </div>
    <div class="col-lg-4 d-flex align-items-stretch">
      <!--CARD HERE-->
    </div>
  </div>
</div>
Copy after login

Option 2: Flexbox Solution for Bootstrap 5

For Bootstrap 5, the following CSS code can be used to achieve equal card heights within card-columns using Flexbox properties:

.card-columns {
  display: flex;
  flex-wrap: wrap;
  align-content: stretch;
}
Copy after login

Example in CodePen

For a live demonstration of this solution in CodePen, please visit the following link:
https://codepen.io/Kerrys7777/pen/QWgwEeG

The above is the detailed content of How to Achieve Equal Card Heights in Bootstrap Card Columns?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template