Bootstrap 4: Achieving consistent card height across different breakpoints

I have a button group inside the footer of my cards that takes up some space. In the past, I wrapped each individual card in a div like this:

  <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-3"></div>

Now, my goal is to ensure that all cards are of the same height. I attempted to achieve this using card decks. While I was successful in setting the height as desired, the cards end up staying adjacent for too long, causing the button group to extend beyond the card's boundaries. Here is an image showing how it looks:

https://i.sstatic.net/Rv3SO.png

I then tried integrating the col-12 specifications into the card tag like so:

  <div class="card col-12 col-sm-12 col-md-6 col-lg-6 col-xl-3 card-col"></div>

Unfortunately, this didn't yield the desired outcome. How can I meet both objectives: ensuring uniform height and sufficient width for the button group?

Specifically, I aim to leverage the height feature of card-deck along with Bootstrap's grid system so that the columns are arranged as follows:

||||

Which should transition to:

||
||

And finally transform into:

|
|
|
|

EDIT - complete code:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<div class="row card-deck">
  <div class="card my-3">
    <div class="card-body">
      <h5 class="card-title">Title</h5>
      <h6 class="card-subtitle mb-2 text-muted">Date</h6>
      <p class="card-text">Description</p>
    </div>
    <div class="card-footer">
      <div class="btn-group" role="group">
        <button type="button" class="btn btn-primary viewActivity">View</button>
        <button type="button" class="btn btn-success editActivity">Edit</button>
        <button type="button" class="btn btn-danger deleteActivity">Delete</button>
      </div>
    </div>
  </div>
</div>

Solution

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  
  <style>
    .card {
      height:100%;
    }
   </style>

  <div class="row">
    <div class="col-12 col-sm-12 col-md-6 col-lg-6 col-xl-3 card-col mb-3">
      <div class="card">
       <div class="card-body">
         <h5 class="card-title"></h5>
         <h6 class="card-subtitle mb-2 text-muted"></h6>
         <p class="card-text"></p>
       </div>
       <div class="card-footer">
       <div class="btn-group" role="group">
         <button type="button" class="btn btn-primary viewActivity">View</button>
         <button type="button" class="btn btn-success editActivity">Edit</button>
         <button type="button" class="btn btn-danger deleteActivity">Delete</button>
       </div>
     </div>
   </div>
 </div>
 </div>

Answer №1

The issue you're facing stems from the default padding in the .card-footer and .btn elements. To achieve a cleaner appearance between 576px and 700px, you can override these paddings as shown below:

Here's a working snippet:

.card-footer {
  text-align: center !important;
  padding: .75rem 0 !important;
}

@media screen and (min-width:576px) and (max-width:700px) {
  .btn {
    padding: .375rem 0.3rem !important;
  }
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<div class="row card-deck">
  <div class="card col-12 col-sm-12 col-md-6 col-lg-6 col-xl-4 card-col">
    <div class="card-body">
      ...
    </div>
    <div class="card-footer">
      ...
    </div>
  </div>
  
  ... (additional card elements)
  
</div>

Make sure to place the style tag after the bootstrap.css link on your page to avoid using !important (which was necessary here for demonstration purposes).

Update: In response to further inquiries:

.card-footer {
  text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container-fluid ">
  <div class="row ">
    <div class="card col-12 col-sm-12 col-md-6 col-lg-6 col-xl-3 card-col">
      ...
    </div>
    
    ... (more card elements)
      
  </div>
</div>

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

Discovering descendant div elements

I've been conducting some research, but I'm struggling to find a specific answer for this. Here is the HTML code snippet: <div class="collapsingHeader"> <div class="listItemWrapper"> <div class="itemWrapper"> ...

How can I center align my loader inside app-root in Angular2+?

I've successfully added a basic spinner to my <app-root> in the index.html file. This gives the appearance that something is happening behind the scenes while waiting for my app to fully load, rather than showing a blank white page. However, I& ...

What is the standard "placeholder" for a Select-box in Angular?

Currently in the process of developing a front-end web application with Angular 6, I have encountered a challenge. Specifically, I am working on creating a component that includes various select-boxes, resembling this setup: https://i.sstatic.net/6DmL9.pn ...

What is the best way to bring in this interface from the React-Particles-JS library?

I have been attempting to segregate my parameters from my JSX within the react-particles-js library. I organize my parameters in an Object: let config = { "particles": { "number": { "value": 50 }, ...

Display a DIV element when a specific date is chosen using bootstrap-datepicker

Looking to incorporate the bootstrap-datepicker plugin using the provided markup... Is there a way to display a DIV element when selecting a specific date and then hide it again when another date is chosen? <head> <script src="https://cdnjs.cl ...

Example of converting PSD design to HTML slicing

Although I am not well-versed in the art of converting PSD to HTML, I am curious to hear from those who are experts in this area. My concern is that when I encounter these types of designs, I immediately think about the large size images (both in terms of ...

Making an asynchronous call from Index.html to PHP Script

I am currently working on implementing an AJAX call to my PHP Script. While I can successfully echo the results from my data.php file, I am now facing a challenge regarding how to initiate the call from index.html in order to retrieve the table results s ...

Controlling the Size of Images

I am currently dealing with a significant issue related to saving bandwidth and storage. My website (built on PHP/Laravel) features 5-6 different image sizes in the desktop view. Whenever a user uploads an image, I am required to save 7 versions of that i ...

How can I dynamically update a <ul> list with AngularJS when a button is clicked or user inputs something?

For those interested, I have created a JSFiddle that can be viewed here I am trying to find a solution to retrieve user input (filename) from the input box and add it as an item in a list within the <ul>. I attempted to use a .push directive alongsi ...

Eradicate white space in a JavaScript code

Calling all JS programmers! Here's a challenge for you, check out this demo: https://codepen.io/gschier/pen/jkivt I'm looking to tweak 'The pen is simple.' to be 'The pen issimple.' by removing the extra space after 'is& ...

The width of the textarea in Bootstrap does not automatically expand to 100% width

The issue here is that the width of the textarea does not match the width of the div below it. Even setting min-width: 100% or using the bootstrap class w-100 doesn't fix this problem. https://i.sstatic.net/93uLa.png <div class="container p-5 ...

Problem with the show/hide feature on jQuery. Automatically scrolls to the beginning of the page

On my website, I have successfully implemented two basic Show / Hide links that are working great. Here is the HTML code: <!DOCTYPE html> <html lang="en"> <head profile="http://gmpg.org/xfn/11"> <meta http-equiv="Content-Type" conte ...

Utilizing the ngIf Statement with a Repeating Element: A Step-by-Step

I am working with an Angular Material table: (HTML) <table mat-table [dataSource]="dataSource" multiTemplateDataRows class="mat-elevation-z8"> <ng-container matColumnDef="{{column}}" *ngFor="le ...

Unable to delete a segment of text within the description of each individual article division using jQuery

In an effort to clean up the article descriptions on my website's homepage, I am seeking a solution to remove the {AC} text that appears at the beginning of each description. While attempting to use the jQuery code provided below, I encountered an iss ...

How can you determine the specific type of "display" utilized by CSS Bootstrap for a particular element?

When manipulating the "display" property of a bootstrap element like "row" or "col-md-3" using JavaScript, how can I determine the default value set by Bootstrap CSS? For instance, the Bootstrap source code likely sets the "display" value for the "row" cl ...

issue with bootstrap modal excessive scrolling when soft keyboard is displayed

I've tried looking for an answer to this issue, but I couldn't find anything relevant. The problem lies with a form inside a bootstrap 4 modal that behaves strangely on mobile devices. When I open the form and tap on an input field, the screen sc ...

Learn how to display or conceal the HTML for 'Share this' buttons on specific routes defined in the index.html file

Currently, I am in the process of updating an existing Angular application. One of the requirements is to hide the "Share this buttons" on specific routes within the application. The "Share" module typically appears on the left side of the browser window a ...

Design a dynamic top navigation bar in Angular or any other framework that automatically adjusts to the size of the screen, similar to the responsive bookmarks bar in

Could you offer guidance or suggestions on how to design a navigation bar (using Angular 1, jQuery, CSS, etc) that emulates the functionality of Google Chrome bookmarks bar when resizing the page? Essentially, as the page size decreases, a new button/symbo ...

Capturing and saving detailed hand-drawn artwork in high resolution

Is there a cutting-edge solution available for capturing hand-drawn sketches (from a tablet, touch screen, or iPad-like device) on a website using JavaScript and saving it on the server side? Essentially, I am looking for a mouse drawing canvas with a hig ...

What is the proper way to include 'rowspan' specific CSS within an HTML table?

I have an HTML table with rowspans in it: table tr, td { border: 1px solid black; } tr:nth-child(1) { background-color: red; } tr:nth-child(2) { background-color: blue; } <table> <tr> <td rowspan=2>Section 1</td> ...