How to Align Bootstrap Buttons at the Bottom of Cards?

Linda Hamilton
Release: 2024-11-09 04:29:02
Original
781 people have browsed it

How to Align Bootstrap Buttons at the Bottom of Cards?

Aligning Bootstrap Buttons at the Bottom of Cards

Problem Statement

When working with Bootstrap's card-deck and card classes, misalignment can occur when one card's content varies in size. This issue is particularly evident when trying to vertically align buttons at the bottom of each card.

Solution

Bootstrap 4 provides modifier classes that offer an elegant solution to this alignment challenge:

  1. Append d-flex to the .card-body
  2. Append flex-column to the .card-body
  3. Append mt-auto to the .btn element nested within the .card-body

Code Modifications

<div class="card-deck">
  <div class="card">
    <div class="card-body d-flex flex-column">
      <p class="card-text">Card 1 content</p>
      <button type="button" class="btn btn-primary mt-auto">Button 1</button>
    </div>
  </div>
  <div class="card">
    <div class="card-body d-flex flex-column">
      <p class="card-text">Card 2 content</p>
      <button type="button" class="btn btn-primary mt-auto">Button 2</button>
      <button type="button" class="btn btn-primary mt-auto">Button 3</button>
    </div>
  </div>
</div>
Copy after login

Conclusion

Utilizing these modifier classes automatically aligns buttons at the bottom of cards, regardless of content variations. This ensures a consistent and visually appealing presentation.

The above is the detailed content of How to Align Bootstrap Buttons at the Bottom of Cards?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!