Alignment of Bootstrap 5 card text and buttons

I've been diving into the BootStrap 5 Crash Course from this YouTube link: https://www.youtube.com/watch?v=4sosXZsdy-s. The final website from the tutorial can be found here:

One specific part focuses on using Cards, but I'm facing an issue where the alignment goes off if the text lengths are different. Here's a snippet of the HTML:

<section class="p-5">
  <div class="container">
    <div class="row text-center g-4">
      <div class="col-md">
        <div class="card bg-dark text-light">
          <div class="card-body text-center">
            <div class="h1 mb-3">
              <i class="bi bi-laptop"></i>
            </div>
            <h3 class="card-title mb-3">Virtual</h3>
            <p class="card-text">
              Lorem, ipsum dolor sit amet consectetur adipisicing elit.
              Iure, quas quidem possimus dolorum esse eligendi?
            </p>
            <a href="#" class="btn btn-primary">Read More</a>
          </div>
        </div>
      </div>
      <div class="col-md">
        <div class="card bg-secondary text-light">
          <div class="card-body text-center">
            <div class="h1 mb-3">
              <i class="bi bi-person-square"></i>
            </div>
            <h3 class="card-title mb-3">Hybrid</h3>
            <p class="card-text">
              Lorem, ipsum dolor sit amet consectetur adipisicing elit.
              Iure, quas quidem possimus dolorum esse eligendi?
            </p>
            <a href="#" class="btn btn-dark">Read More</a>
          </div>
        </div>
      </div>
      <div class="col-md">
        <div class="card bg-dark text-light">
          <div class="card-body text-center">
            <div class="h1 mb-3">
              <i class="bi bi-people"></i>
            </div>
            <h3 class="card-title mb-3">In Person</h3>
            <p class="card-text">
              Lorem, ipsum dolor sit amet consectetur adipisicing elit.
              Iure, quas quidem possimus dolorum esse eligendi?
            </p>
            <a href="#" class="btn btn-primary">Read More</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

I attempted adding h-100 to the card-body, which equalized the card heights but resulted in misaligned buttons at the bottom.

Any tips on maintaining consistent card height while keeping buttons aligned correctly?

Thanks!

Answer №1

If you want to experiment with the flex CSS property, I can show you how using your existing code.

  1. Add .h-100 to .card
  2. Include .d-md-flex and .flex-column in .card-body
  3. Apply .flex-grow-1 to .card-text

Voila~ This is just one way to achieve the layout you're looking for, but keep in mind that it may vary based on screen size requirements.

For a complete guide on flexbox capabilities in Bootstrap 5, check out this page.

I hope this information proves useful!

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83e1ececf7f0f7f1e2f3c3b6adb0adb3aee2eff3ebe2b2">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">

<section class="p-5">
  <div class="container">
    <div class="row text-center g-4">
      
      <div class="col-md">
        <div class="card bg-dark text-light h-100">
          <div class="card-body text-center d-md-flex flex-column">
            <div class="h1 mb-3">
              <i class="bi bi-laptop"></i>
            </div>
            <h3 class="card-title mb-3">Virtual</h3>
            <p class="card-text flex-grow-1">
              Lorem, ipsum dolor sit amet consectetur.
            </p>
            <a href="#" class="btn btn-primary">Read More</a>
          </div>
        </div>
      </div>
      
      <div class="col-md">
        <div class="card bg-secondary text-light h-100">
          <div class="card-body text-center d-md-flex flex-column">
            <div class="h1 mb-3">
              <i class="bi bi-person-square"></i>
            </div>
            <h3 class="card-title mb-3">Hybrid</h3>
            <p class="card-text flex-grow-1">
              Lorem, ipsum dolor sit amet consectetur adipisicing elit.
            </p>
            <a href="#" class="btn btn-dark">Read More</a>
          </div>
        </div>
      </div>
      
      <div class="col-md">
        <div class="card bg-dark text-light h-100">
          <div class="card-body text-center d-md-flex flex-column">
            <div class="h1 mb-3">
              <i class="bi bi-people"></i>
            </div>
            <h3 class="card-title mb-3">In Person</h3>
            <p class="card-text flex-grow-1">
              Lorem, ipsum dolor sit amet consectetur adipisicing elit.
              Iure, quas quidem possimus dolorum esse eligendi?
            </p>
            <a href="#" class="btn btn-primary">Read More</a>
          </div>
        </div>
      </div>
      
    </div>
  </div>
</section>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating unique page styles using global styles in Next.js

I am facing a dilemma in my NextJS app. On the /home page, I need to hide the x and y overflow, while on the /books page, I want the user to be able to scroll freely. The issue is that Next only allows for one global stylesheet and using global CSS selec ...

Tips for deleting directory path from a file name

Similar Question: How to extract file name from full path using PHP? echo '<td width="11%" class="imagetd">'. ( ( empty ($arrImageFile[$key]) ) ? "&nbsp;" : htmlspecialchars( is_array( $arrImageFile[$key] ) ? implode(",", $arrImag ...

The alignment of the textarea is off due to an issue with the md

I'm experiencing an issue with the alignment of options in my form. The md-maxlength attribute is causing one line to be higher than the rest, as shown in the image below. https://i.sstatic.net/3J3Ts.png My goal is to move that specific textarea one ...

Is it possible to alter the appearance of my menu when clicked on?

Is there a way to update the appearance of an active menu or submenu that is selected by the user? I would like the chosen submenu and its parent menu to have a distinct style once clicked (similar to a hover effect, but permanent). /*jQuery time*/ $(do ...

merge PHP variables together

Currently in the process of constructing a string for the picture information in a lightbox gallery display. Initially, I used this snippet: <td><div style='height:175px;'></div></td><td><a href='images/memw ...

Troubleshooting the issue: Unable to shift a div to the left in a Rails app using jQuery and CSS when a mouseover event occurs

Hey there, I'm working on a div that contains a map. My goal is to have the width of the div change from 80% to 50% when a user hovers over it. This will create space on the right side for an image to appear. I've been looking up examples of jqu ...

What causes the div to not adjust to the browser window when the vertical size is decreased?

Imagine a basic HTML page like this: <doctype> <html> <head> <title>My Amazing Page</title> <script type="text/javascript" src="jquery-1.8.3.min.js"></script> </head&g ...

What is the reasoning behind jQuery UI employing CSS classes as opposed to pseudo-classes?

In this detailed explanation found on this website, it is discussed why jQuery UI uses CSS classes like .ui-state-active that are applied through JavaScript, rather than utilizing existing CSS pseudo-classes like :active. What is the reasoning behind thi ...

Unfortunately, the header and footer are not lining up correctly with the main body on our mobile site

I've been tasked with creating a fully responsive website, but I'm encountering difficulties with the mobile design. Specifically, when I switch to mobile dimensions like an iPhone 12, the header and footer don't line up properly with the ma ...

Modify the div's background color specifically with AngularJS

After creating a list using divs, my goal is to modify only the background color of the selected div when a user makes a choice from the list. I have accomplished this by defining two distinct CSS classes with the main difference being the background colo ...

Dropped down list failing to display JSON data

I created a website where users can easily update their wifi passwords. The important information is stored in the file data/data.json, which includes details like room number, AP name, and password. [ {"Room": "room 1", "AP nam ...

Querying the database to check for the presence of a file in a .js file on Google App Engine

I'm currently working on implementing an upload button for users to upload files to our storage system using Google App Engine with Python, as well as HTML and JavaScript for the views. To achieve this, we have an HTML file and a.js script that promp ...

What is the best way to link to a CSS file located in a different directory while being in a subdirectory?

For a project I am working on, I am developing a simple streaming site and have organized my files into different folders. These folders include: HTML CSS Shows Within the "Shows" folder, there is a subfolder named "Testshow". I am facing an issue with ...

Arrange three div elements to create a layout that is optimized for different screen sizes

Is there a way to align these 3 divs as follows: pickup on the left, phone in the middle, and delivery on the right? I've browsed through similar alignment issues on Stack Overflow, but none of the solutions seem to work for my specific code. It' ...

What is the best way to create a fully clickable navbar item for the Bootstrap dropdown feature?

I'm struggling to make a button in a navbar fully clickable for the dropdown to open. Even when I try adding margin instead of padding, it only makes things worse. Can someone help me figure out what mistake I'm making here? Essentially, my goal ...

Unable to resize images in Firefox

Why is it that resizing doesn't seem to work in Firefox but functions fine in Internet Explorer? I'm struggling to find a way to make it consistent across all browsers. My goal is to resize the width to 800 and height to 475, disable maximizing t ...

stop the leakage of CSS and JS from the subtree to the document through the inverse shadow DOM mechanism

My page contains dynamic HTML content that I want to incorporate. The dynamic content consists of only HTML and CSS, without any JavaScript. However, I have some custom global CSS styles and JS logic that need to be implemented along with this dynamic con ...

Is there a way to successfully submit multiple locations, each separated by commas, through the multipart form?

Here is my HTML form: <form method="POST" enctype="multipart/form-data" v-on:submit.prevent="handelSubmit($event);"> <div class="clear"> <div class="col-md-3"></div> <div class="col-md-6"> <div class="form ...

Using GeoIP2() in Django models to retrieve data saved from an IP address call and present it in my HTML

I have developed a function that extracts the IP address and saves information from the city_data in GeoIP2(). My goal is to retrieve the Latitude and longitude from the city_data and showcase it on my HTML page. The issue I am facing is the inability to ...

Discovering elements using Selenium in a JavaScript popup box

The issue at hand is rather straightforward. I am faced with the task of clicking on an element within a popup that has been dynamically generated by JavaScript code. The challenge arises as the page is solely accessible in Internet Explorer and the elemen ...