Stop the card from growing within a deck of cards

I encountered a problem with my card-deck layout that I need help solving. Despite wanting to maintain the same adaptive width for the cards, when there are 5 cards in a row, the last two cards end up taking up the full width of the container.

Here's what it should look like (iPad example)

https://i.sstatic.net/BBrKH.png#

This is what it currently looks like (iPad example)

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

You can also see the issue on widescreen displays here: https://i.sstatic.net/LOEF6.png

An example of the code with 5 cards

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

                <div class="container">
                    <div class="card-deck">

                        <div class="card mb-4">
                            <img class="card-img-top img-fluid" src="//placehold.it/500x280" alt="Card image cap">
                            <div class="card-body">
                                <h4 class="card-title">Card title</h4>
                                <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
                                <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
                            </div>
                        </div>

                        (repeated card structures)

                        <div class="w-100 d-none d-md-block d-lg-none"><!-- wrap every 3 on md--></div>

                        (more repeated card structures with wrapping divs)

                    </div>
                </div>

I came across this thread https://github.com/twbs/bootstrap/issues/19650 and attempted using:

.card {
    width: initial;
}

But unfortunately, it did not fix the issue.

Answer №1

The documentation clarifies that card-deck's lack responsiveness, making it challenging to achieve the desired layout without extensive additional CSS. This is due to the behavior of flexbox children (cards) expanding in width.

Instead, consider using full-height cards in the grid...

<div class="row">
        <div class="col-md-4 col-sm-6 pb-4">
            <div class="card h-100">
                ....
            </div>
        </div>
        <div class="col-md-4 col-sm-6 pb-4">
            <div class="card h-100">
                ....
            </div>
        </div>
        <div class="col-md-4 col-sm-6 pb-4">
            <div class="card h-100">
                ....
            </div>
        </div>
          .... (more columns with cards)
</div>

https://www.codeply.com/go/hs12dUxHnQ

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 a function to update data in a Node.js/MongoDB environment

Hey there! I'm new to working with nodejs and mongodb, and I'm trying to create a function that updates the win, lose, and draw record in my UserSchema. Here's my Schema: UserSchema = new mongoose.Schema({ username:'string', ...

Having trouble with the Bootstrap 5 modal in the initial template?

I'm encountering an issue with setting up a basic modal using the Bootstrap 5 starter template paired with the Bootstrap Bundle including Popper. Despite reviewing similar problems on other platforms, none of the solutions seem to resolve my specific ...

Error message: Issue encountered while rendering Angular Bootstrap accordion template

Despite my attempts to find a solution before reaching out for help, I am struggling to get the accordion feature to work in my Angular and Bootstrap application utilizing ui.angular.js. The error message in the developer tools indicates an issue with the ...

Tips for Switching Button Class Triggered by Click Event

I have 2 buttons and I would like to indicate the active button by changing the button class. I attempted to achieve this using removeClass and addClass but encountered an error. Error: removeClass is not a function .component.html <div class="col" ...

What is the best way to distinguish automatically generated links using JavaScript?

(Hello Dr. Nick) JavaScript is a new area for me and I am currently working on creating a website using asp.net EF JavaScript and other tools... I have created links based on the information stored in my database, and I want the name of the link to appea ...

Automatically remove the entered data

Let's say I have a text input field with the initial value of "insert text here" coded like this: <input type="text" value="insert text here" /> What I want is for the text inside the input field to disappear automatically when the user clicks ...

Why is it important to have specific property names?

Here is some code and HTML for triggering a radio button. It seems to work fine without any issues, but I'm wondering if the presence of a name property is necessary. When I remove the name property, it stops working. Can someone explain why? <inp ...

Locate a URL within a Java string and generate an HTML hyperlink tag

My string contains the following: content = "Hello world, visit this link: www.stackoverflow.com"; or content = "Hello world, visit this link: http://www.stackoverflow.com"; or content = "Hello world, visit this link: http://stackoverflow.com"; Now I ...

Is there a way to utilize JQuery to swap out a CSS background image while preserving the gradient effect?

Currently, I am facing a challenge in dynamically updating the background-image property of a div while preserving other background-related properties (such as color and gradient) using jQuery's .css() function. Although I can successfully replace the ...

Learn the method to display a particular post using its unique post ID

I need some help displaying two specific posts by utilizing their post IDs. I'm struggling with the code to retrieve and call these post IDs. Can someone assist me? /////////////////////////////// ////////////////////////////// <div class="foo ...

Hide the entire TR if Mysql equals zero

How can I apply the style "display: none;" to an entire TR if the result from row credits is 0? Should I achieve this using CSS or a MySQL query? <?php $username = "root"; $password = ""; $database = "aaa"; $mysqli = ne ...

Intermediate Push-Pull Training Classes

Hello, I am seeking advice on how to shift a sidebar to the left of the layout while maintaining the order of elements in the HTML. Specifically, I want the sidebar to appear as the 4th element, aligned to the top of the page. This adjustment is primarily ...

Utilize CSS Animation to bring overlapped images to life

Trying to replicate the animation featured on the CISO website header. I have created a JSFiddle demo showcasing my attempt, but it seems like something is not quite right. img { transition: all .3s ease; overflow: hidden ...

Determining Whether a Specific Value Exists in the JQuery Selector '.name'

Is there a way to check if a specific value exists within the elements with the class of $('.name')? I'm already looping through an array to look for each entry in $('.name'), so I can't iterate over $('.name') as we ...

The page fails to load when redirected, however, it briefly displays the page upon clicking the back button before navigating back to the previous page

Currently, I am working with Angular 2 and encountering an issue when attempting to click on a link. The loading bar continues to progress without displaying the data or HTML content on the page. Furthermore, if I try to go back to the previous page, the i ...

During the test execution, ASP.NET Textbox does not appear on the screen

I'm currently working on a project for this semester, but I'm facing an issue with my ASP webform. Whenever I test my application, the ASP text box seems to vanish mysteriously. Is there a way to ensure that the text box remains visible during a ...

What is the best way to align my logo image and search field at the center of the page, similar to the layout of

Struggling with styling this webpage. I aim to have my logo and search bar centered on the page, surrounded by ample space above and below. You can check it out at NE1UP dot com. All I want is a Google-style layout for my page, but I'm facing difficu ...

Can I only highlight the ui-icon when active on a button, instead of the entire button? Specifically related to jQuery Mobile

I am working on a project that involves a footer and navbar containing buttons with icons and text. My goal is to make the icon and text highlight individually when selected, rather than the entire button. Can jQuery Mobile help achieve this effect? Here ...

Looking for a vertical scrollbar solution for your idangerous vertical swiper?

Incorporating idangerous vertical swiper with two slides in a mobile app through jquery mobile has proven challenging. Specifically, I am struggling to implement a vertical scroll bar in the second slide due to its fixed height and the potential collision ...

Is it possible to utilize CSS to generate a full-width slider while maintaining the aspect ratio of the content?

I am currently utilizing the unslider plugin to design a full-width slider header on a webpage (). Although it functions well at the dimensions I set it up for (1920x450), issues arise when viewed on different screen resolutions. See below: The background ...