The Bootstrap justify-content-around is causing the last item to be out of

My current prototype Website has this layout, utilizing justify-content-around: https://i.sstatic.net/WUJdl.jpg

I am seeking a solution for when there is an odd number of cards, ensuring that the final card aligns with the rest. Is there a way to achieve this using justify-space-around instead of space-between?

Below is the snippet of my source code:

    <div class="container-fluid">
        <div class="container-fluid row justify-content-around cards ml-0">
            <div class="card col-12 col-md-5 col-lg-4 col-xl-3 mb-4 mx-1">
                <img src="../images/lit.svg" class="card-img-top" alt="alternative">
                <div class="card-body">
                    <h5 class="card-title">Card title</h5>
                    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                    <a href="#" class="btn btn-primary">Go somewhere</a>
                </div>
            </div>
            <div class="card col-12 col-md-5 col-lg-4 col-xl-3 mb-4 mx-1">
                <img src="../images/lit.svg" class="card-img-top" alt="alternative">
                <div class="card-body">
                    <h5 class="card-title">Card title</h5>
                    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                    <a href="#" class="btn btn-primary">Go somewhere</a>
                </div>
            </div>
            <div class="card col-12 col-md-5 col-lg-4  col-xl-3 mb-4 mx-1">
                <img src="../images/lit.svg" class="card-img-top" alt="alternative">
                <div class="card-body">
                    <h5 class="card-title">Card title</h5>
                    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                    <a href="#" class="btn btn-primary">Go somewhere</a>
                </div>
            </div>
        </div>
    </div>

In an additional CSS file, I included the following:

.cards::after{
    content: '';
    flex: auto;
}

This ensures that the last item remains on the left side rather than in the center!

Thank you for your help!

Answer №1

Make the switch from col-md-5 to col-md-4. I have provided an example below for your reference:

    <div class="card col-12 col-md-4 col-lg-4 col-xl-3 mb-4 mx-1">
        <img src="../images/lit.svg" class="card-img-top" alt="alternative">
        <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            <a href="#" class="btn btn-primary">Go somewhere</a>
        </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

Issue encountered when attempting to connect an external script to a Vue single file component

Struggling to link an external script to a single file component in Vue. My project setup is as follows: https://i.sstatic.net/LWvNx.png I need to link the file components/Sshy to ../javascripts/ I have successfully linked other scripts using either of ...

A guide to implementing Stateful Bootstrap 4 Tab Navigation in Rails 6

I am currently facing an issue with my Rails 6 app that uses Bootstrap 4's tab component. The tabs work smoothly, but it creates a poor user experience when the tab resets to default after refreshing or navigating forwards and backwards. I specificall ...

Keep the nested ul with absolute positioning open until the pointer is moved outside the element

I am working on a navigation menu where the last list item (li) contains a nested ul for a dropdown menu. My goal is to display this nested menu when hovering over the parent li and hide it when moving away from the menu. However, I am running into an issu ...

Content overflowing the container - Designed to adapt to different screen sizes

I'm currently working on a project within the Bootstrap 3 framework and struggling with an issue regarding text overflow in extra small view. The text is not behaving as expected, as it should stick to its container and break accordingly. I've ex ...

What could be the underlying reason for the unusual behavior observed in this range polyfill implementation?

I am attempting to transform an HTML5 range input into a set of radio buttons. Each radio button corresponds to a value within the original range, with text displaying its value. However, I am encountering an issue where the last piece of text, meant to sh ...

What is the best way to align multiple form elements both horizontally and vertically within a frame?

Issue I have checked out various resources, like this one and this one, but I am still struggling to center my form elements both vertically and horizontally on the screen. I have tried using flex, padding, and stretching but nothing seems to work. Even a ...

Tips for aligning objects within a bootstrap column so that they all have the same starting point on the X axis

To recreate the issue I am facing, I created a basic HTML structure with 2 bootstrap columns. My aim is to have multiple <p> elements in the second column, stacked one below the other. However, the problem arises when these <p> tags contain tex ...

What is the best way to place a list within a <div> element?

There is a <div> with an image in the background. I now want to include a list within that div, but I'm having trouble positioning it. Check out this image for reference In the image above, you can see the background and the list, but I'm ...

Keep the footer at the bottom of the screen without needing to define a 100vh in Material UI

In the process of developing my react app with MUI framework, I encountered various challenges in creating a sticky footer at the bottom of my screen. After exploring different solutions, one approach that I found most satisfactory is as follows: export de ...

Gallery of Disappearing Images

I am encountering issues with the image gallery on my website, as it seems to create a space to the right when viewed on screens smaller than 350px. This results in a gap on the entire right side of the page. My goal is to make this image gallery responsiv ...

The Bootstrap Navbar is causing the navigation bar to span across two lines

I'm having an issue with my navbar taking up two lines on desktop resolution, but fitting perfectly on mobile. I've spent hours going through the code with no success. Any help would be greatly appreciated. The HTML code is provided below. <! ...

What is the best way to create clickable dynamic HTML table data using jQuery?

I'm fairly new to this, but I've managed to successfully create an HTML table dynamically using jQuery. Below is the code that I used: Is there a way to make the table data (value.id) clickable so that it can redirect to a different page? $(d ...

Clearing selections from a multiple-choice input field

I am seeking to implement a delete feature in a multi-select element similar to the functionality seen here on stackoverflow when selecting multiple tags for a question. Once an item is selected, I would like to display a close icon next to it so that user ...

I am interested in implementing a "slide up" effect for the "slide menu" when it loses focus

When I focus out of the asmenu class, I attempt to trigger a 'slide up' effect. However, if I select two checkboxes from the child elements within the asmenu class, the focusout event is still triggered. Ideally, I would like the 'slide up& ...

Is there a faster alternative to using jQuery's indexOf method?

Looking to create a search box for a large set of options (around 2000 options) The indexOf method is very slow...any alternative solutions? Jquery Code : $('#textfortitlesearch').on('keyup', function() { var query = this.value ...

What causes the child div to not be centered when using margin and border box?

<style> .parent { width: 300px; height: 300px; border: 1px solid red; padding: 20px; } .child { box-sizing: border-box; margin: 20px; width: 100%; height: 100%; ...

Transferring multiple parameters between components using Navigate and ParamMap

My concern is that I'm unsure of how to pass multiple parameters through the component's route. I need to send two attributes. Is there a specific syntax required in defining the route? Below is my desired functionality for passing the attribut ...

Desktop users will not see the mobile navigation bar

I'm working on creating a sidebar navigation that stays fixed on desktop but collapses on mobile devices. The issue I'm facing is that once I toggle the navigation on mobile, it remains toggled and doesn't show up on desktop. Check out my co ...

Adding the "orientation media query" to Bootstrap 4 sass media query is a straightforward process that can enhance the responsiveness of your

Currently, I am utilizing the "vanilla" bootstrap 4 sass media query within my scss files: @include media-breakpoint-up(xs){} @include media-breakpoint-up(sm){} @include media-breakpoint-up(lg){} @include media-breakpoint-up(xl){} I am aware that using t ...

Apply a new class to all Radio buttons that were previously selected, as well as the currently

Struggling with a simple code here, trying to figure out how to add color (class) to the selected radio button and the previous ones. For example, if button No3 is selected, buttons 1, 2, and 3 should get a new color. Below is the basic code snippet: < ...