Home >Web Front-end >CSS Tutorial >How to Make Bootstrap 4 Card-Columns Cards of Equal Height?

How to Make Bootstrap 4 Card-Columns Cards of Equal Height?

Barbara Streisand
Barbara StreisandOriginal
2024-11-26 04:11:07414browse

How to Make Bootstrap 4 Card-Columns Cards of Equal Height?

Making Bootstrap Cards of Equal Height in Card-Columns

In Bootstrap 4, the card-columns class is used to display cards in columns, but cards may vary in height depending on their content. To achieve equal height cards, we can use a combination of CSS and flexbox.

Solution:

Instead of setting a fixed minimum height on the cards, we can use the align-items-stretch utility on the column elements within the card-columns. This makes the columns stretch to the full height of the tallest card.

.card-columns .col {
    align-items: stretch;
}

Implementation:

Wrap your card-columns within a container and each card within a column as follows:

<div class="container">
    <div class="row">
        <div class="col-lg-4 align-items-stretch">
            <div class="card">
                <!-- Card content -->
            </div>
        </div>
        <div class="col-lg-4 align-items-stretch">
            <div class="card">
                <!-- Card content -->
            </div>
        </div>
        <div class="col-lg-4 align-items-stretch">
            <div class="card">
                <!-- Card content -->
            </div>
        </div>
    </div>
</div>

Note:

  • Ensure that the column widths (col-lg-4 in this example) are equal for all columns.
  • If there are any background or borders on the cards, you may need to adjust the CSS to ensure the borders and backgrounds align correctly.

The above is the detailed content of How to Make Bootstrap 4 Card-Columns Cards of Equal Height?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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