Home  >  Article  >  Web Front-end  >  How to Create Equal-Height Cards Within Bootstrap 4 Columns?

How to Create Equal-Height Cards Within Bootstrap 4 Columns?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-29 18:53:02196browse

How to Create Equal-Height Cards Within Bootstrap 4 Columns?

Bootstrap 4 Equal-Height Cards Within Columns

Issue

Many developers utilizing Bootstrap 4 encounter a common issue: cards within columns often vary in height, primarily due to differences in content or heading size. This can create an uneven and visually unappealing layout.

Solution

To achieve equal-height cards within Bootstrap 4 columns, leverage the h-100 class to set the height of the cards to 100% of the containing column. This ensures that the cards occupy the full height of the available space.

Implementation

HTML Markup:

<code class="html"><div class="container">
  <div class="row">
    <div class="col-md-4 col-sm-6 col-12">
      <div class="card h-100">
        ...
      </div>
    </div>
    ...
  </div>
</div></code>

Note:

  • The .col-* classes should be applied directly to the .card div, not to an intermediate element like .card-deck.
  • Using float on the cards is unnecessary.
  • The h-100 class can be applied to all cards within a column or selectively to specific cards for targeted height adjustments.

Example Code (Codeply):

https://codeply.com/go/hKhPuxoovH

The above is the detailed content of How to Create Equal-Height Cards Within Bootstrap 4 Columns?. 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