Home > Web Front-end > CSS Tutorial > How to Create Equal-Height Bootstrap Cards in Card Columns?

How to Create Equal-Height Bootstrap Cards in Card Columns?

Susan Sarandon
Release: 2024-11-25 00:23:19
Original
928 people have browsed it

How to Create Equal-Height Bootstrap Cards in Card Columns?

Equal Height Bootstrap Cards in Card Columns

When using Bootstrap's card-columns class, cards of different heights can create an uneven layout. To achieve equal height cards, consider the following solutions:

Using align-items-stretch on Columns

In the parent row containing the card-columns class, add the utility class d-flex align-items-stretch to each column. This will align the card content vertically, effectively creating cards of equal height:

<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

Example for Bootstrap 5 (BS5)

The following full HTML example demonstrates the align-items-stretch solution in BS5:

<div class="container">
    <div class="row">
        <div class="col-md-4">
            <div class="card mb-4">
                <img src="..." alt="" class="card-img-top">
                <div class="card-body">...</div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card mb-4">
                <img src="..." alt="" class="card-img-top">
                <div class="card-body">...</div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card mb-4">
                <img src="..." alt="" class="card-img-top">
                <div class="card-body">...</div>
            </div>
        </div>
    </div>
</div>
Copy after login

The above is the detailed content of How to Create Equal-Height Bootstrap Cards in 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