Having trouble with Bootstrap card deck's card heights not aligning?

Struggling to align Bootstrap's card deck vertically? One card with shorter text is causing a mismatch and you're not sure how to fix it.

On the same page, you want three cards displayed horizontally on desktop and stacked vertically on mobile. That's why you added extra margin in your CSS file.

<div class="container mw-100 h-100">
    <div class="row h-100 align-items-center">
        <div class="col-12 col-md-6 col-lg-4 col-xl-4">
            <div class="card">
                <img class="card-img-top" src="img1.jpg" alt="img1" />
                <div class="card-body">
                    <h5 class="card-title">Title 1</h5>
                    <p class="card-text">
                        Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero voluptas, vero voluptatibus odio nostrum facilis aut! Dolores, non accusamus. Sapiente et minus sint numquam. Labore laborum ut a commodi doloremque.
                    </p>
                    <p class="card-text">
                        <button type="button" class="btn btn-dark btn-lg" onclick="startGame()">Start</button>
                    </p>
                </div>
            </div>
        </div>
        <div class="col-12 col-md-6 col-lg-4 col-xl-4">
            <div class="card">
                <img class="card-img-top" src="img2.jpg" alt="img2" />
                <div class="card-body">
                    <h5 class="card-title">Title 2<span class="badge badge-secondary">New</span></h5>
                    <p class="card-text">
                        Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero voluptas, vero voluptatibus odio nostrum facilis aut! Dolores, non accusamus. Sapiente et minus sint numquam. Labore laborum ut a commodi doloremque.
                    </p>
                    <p class="card-text">
                        <button type="button" class="btn btn-dark btn-lg">Start</button>
                    </p>
                </div>
            </div>
        </div>
        <div class="col-12 col-md-6 col-lg-4 col-xl-4">
            <div class="card">
                <img class="card-img-top" src="img3.jpg" alt="img3" />
                <div class="card-body">
                    <h5 class="card-title">Title 3<span class="badge badge-secondary">New</span></h5>
                    <p class="card-text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Libero voluptas, vero voluptatibus odio nostrum facilis aut! Dolores, non accusamus. Sapiente et minus sint numquam. Labore laborum ut a commodi doloremque.</p>
                    <p class="card-text">
                        <button type="button" class="btn btn-dark btn-lg">Start</button>
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>

To align the container itself, add height in the CSS along with some margins and regular browser reset properties.

* {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
}
html,
body {
    height: 100%;
}

.card {
    margin-bottom: 0.75rem;
}

.row :first-child > .card {
    margin-top: 0.75rem;
}

Answer №1

The reason for this issue is that your items are currently aligned to the center with

<div class="row h-100 align-items-center">
. To fix this, you need to change it to align to the top with
<div class="row h-100 align-items-top">
. This modification should be made on the 2nd line of your html code. For reference, please check out this link: https://jsfiddle.net/wp406n8d/4/

Furthermore, you can remove the following code snippet:

.row :first-child > .card {
    margin-top: 0.75rem;
}

Also, if you wish to ensure all cards have the same height, consider adding height: 100% to the .card class. Here's an example of how it can be implemented: https://jsfiddle.net/7ah6f4mo/

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

How can you implement a transform transition toggle when a user clicks on an element

Check out this CodePen example for a cool overlay animation: https://codepen.io/pen/MoWLrZ Experience the unique animation of two overlays as you click for the first time. However, on the second click, watch as both overlays seamlessly return to their ori ...

Tips for seamlessly combining Bootstrap with Vue.js

Is there a solution for the error message that keeps showing up? https://i.sstatic.net/t2fOe.png ...

Challenges with navbars and Bootstrap

Just started using twitter-bootstrap and I'm trying to customize the navbar by removing borders and padding, adding a hover effect for links with a different background color, and setting margins of about 10px on the left and right. However, I'm ...

Can anyone recommend a high-quality jQuery lightbox replica?

Key Features Needed: Customizable with CSS Capable of handling forms, not just images Extensively documented Please provide any recommendations and suggestions for suitable options. Thank you in advance ...

What kind of GWT component features both a Button and text?

I am looking to develop a customized GWT widget that consists of a rectangular div element resembling a button, accompanied by text positioned adjacent to it. My goal is to enable the selection of this widget so that clicking on either the div/button or th ...

How to maintain HTML list items in a single line while overlaying text

I'm seeking assistance with understanding how to solve a particular issue. I have multiple list elements with varying lengths of text content, each flanked by small images/icons on either side. Below is an example of the HTML structure: .truncate ...

Position: fixed CSS child element ignoring parent's layout constraints

When a parent element is positioned (using position: relative or position: absolute) and contains a child element with position: absolute, the child element will be positioned absolutely inside the parent. A child element with position: sticky will behave ...

Implementing a consistent CSS structure for various media sizes

Utilizing CSS grid and Sass, I implement varying grid layouts for different screen sizes (phone, tablet, desktop). However, on certain pages, I desire the same layouts at slightly larger or smaller screens than others. Is there a way to achieve this witho ...

Ways to adjust dimensions depending on zoom level or screen size

Here is the HTML code snippet: <div id="divMainFirst"> <div id="divInnerFirst"> <div id="divTitleHeaderUC"> <span id="spanTitleHeaderUC">Urgent Care Wait Time</span> </d ...

No reaction being triggered by the CSS Media Query

I'm attempting to have the title-image stay static when the screen size is below 1052px so that it fills the full width of the viewport, but the styles should only be applied when the screen size is less than 992px. This is from the Web Development co ...

I can't figure out why my unslider isn't adapting to the screen size. Check out the fiddle for more details

I recently implemented unslider to create a slideshow that spans 100% of the width on my website. Everything seemed to be working fine until I tried resizing the screen, and the slides remained the same size as they were initially loaded. Here is the code ...

Navigate to a specific section of a webpage with automatic scrolling

I'm developing a Chrome App and incorporating the web view tag, which functions similarly to an iframe. Is there a way to load a webpage inside the web view halfway down the page? I have attempted the following: application.js: $(document).ready(f ...

How can you tell if a contenteditable div is currently in focus?

Essentially, my setup consists of: HTML: <div class="div1"> <div class="as-text-box" contenteditable="true"></div> </div> CSS: .div1{ position:absolute; height:50px; width:200px; background:white; border:1px solid #c ...

Ways to widen CSS style in an HTML file in order for it to be visible across the entire page when viewed in a browser

I am trying to make my div stretch across the entire width of the web browser window. However, I noticed that when I scroll to the right side of the page, the div style gets cut off. .div3{ background-image: url('images.jpeg'); b ...

Is the jQuery popup malfunctioning? It appears to be stuck within a div

Currently, I am in the process of developing a website at and I am facing an issue with the hover type menu. Whenever I click on the arrows next to the logo, instead of fully opening up, the menu seems to be getting stuck and is not expanding entirely. I ...

Issues with the radio-inline class in Angular and Bootstrap causing functionality errors

Trying to align my radio buttons on one line using the radio-inline class from bootstrap. Here's my code: <label>Fattura a carico di </label> <label class="radio-inline control-label"><input type="radio" value="banca" n ...

Tips for resolving a sluggish webpage with database content

I am facing an issue with one specific page on my website that contains links to the database. The loading speed of this page is extremely slow and I'm looking for ways to speed it up. I have noticed that even when there are no visitors on the server ...

How to Place a Button Halfway Out of an Angular 5 Material Dialog

Is there a way to place a close button on the top right corner of a dialog box, partially inside and outside the dialog like shown in this image: I attempted using absolute positioning to achieve this, but that solution is not ideal. I want to position t ...

What is the best way to style this specific HTML code using CSS?

Currently, I am facing an issue where two sets of text that are supposed to be inline with each other are not aligned properly. One of the texts is placed higher than the other even though they share the same CSS code. I want to be able to edit only one se ...

Stylish Material Design Icons

Our website utilizes CSS classes to display icons across various pages. .alert { /* used for "alert" type messages */ background: url(images/alerts.png) no-repeat left top; padding: 5px 0 15px 35px; margin: 0; } Use: <p id="ctl00_ctl00_ContentMessagePa ...