Home > Web Front-end > CSS Tutorial > How to Align Buttons at the Bottom of Bootstrap Cards with Different Content Lengths?

How to Align Buttons at the Bottom of Bootstrap Cards with Different Content Lengths?

DDD
Release: 2024-11-11 05:41:03
Original
248 people have browsed it

How to Align Buttons at the Bottom of Bootstrap Cards with Different Content Lengths?

Aligning Buttons at the Card Bottom using Bootstrap

One common challenge encountered while working with Bootstrap card decks is aligning buttons vertically when some cards have fewer items. The issue arises due to differences in list lengths among cards.

To address this, you can employ the following Bootstrap 4 modifier classes:

  1. d-flex to .card-body: This establishes a flexbox container for the card body.
  2. flex-column to .card-body: Sets the flexbox container to a vertical direction.
  3. mt-auto to .btn nested in .card-body: Adds automatic spacing to position the button at the bottom of the container.

HTML Example:

<div class="card">
  <div class="card-body d-flex flex-column">
    <ul class="list-group list-group-flush">
      <li class="list-group-item">Item 1</li>
      <li class="list-group-item">Item 2</li>
    </ul>
    <button class="btn btn-primary mt-auto">Button</button>
  </div>
</div>
Copy after login

Fiddle Demonstration:

Refer to the following fiddle for a live demonstration: https://jsfiddle.net/IGN7K/

By implementing these classes, you can ensure that buttons are consistently aligned at the bottom of all cards, regardless of their content length.

The above is the detailed content of How to Align Buttons at the Bottom of Bootstrap Cards with Different Content Lengths?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template