Bootstrap 5: Card-carousel combination results in inconsistent sizes

Check out the issue in this GIF:

I am currently using Bootstrap 5 to incorporate a carousel within a card. However, as the images transition, the card size changes accordingly. My goal is to maintain a consistent size for all images without any resizing of the card.

Below is the relevant code snippet:

           <div class="col">
                <div class="card h-100">
                    <div class="card-img-top w-100">
                        <div id="carouselExampleControls" class="carousel slide >
                            <div class="carousel-inner">
                                <div class="carousel-item active
                                    <img src="1.png" class="d-block w-100 " alt="..." >
                                </div> 
                                <div class="carousel-item active
                                    <img src="2.png" class="d-block w-100 " alt="..." >
                                </div>
                                <div class="carousel-item active
                                    <img src="3.png" class="d-block w-100 " alt="..." >
                                </div>

                            </div>
                            <Button stuff, not so important...>
                        </div>
                    </div>

                    
                    <div class="card-body">
                        <h5 class="card-title">a title</h5>
                        <p class="card-text">Some text.</p>
                    </div>
                    <div class="card-footer">
                        Some Text here.
                    </div>
                </div>
            </div>

Does anyone have any suggestions on how to solve this?

Answer №1

To achieve the desired result, you should specify a fixed height or width for the image element.

Apply some CSS to the img tag to control the image's dimensions and alignment. You can use the following code snippet:

.gallery img {
    height: 300px;
    width: 100%;
    object-fit: contain;
    object-position: center;
}

The object-fit: contain; property ensures that the image fits without distortion, while object-position: center; centers the image vertically within the container of 300px in height. Check out this live example: https://www.example.com/p/q98BsklD21

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

Enhance Your Page with a Widget Using Bootstrap

I am looking to incorporate a basic text box on the side of my webpage. https://i.sstatic.net/qzwIh.png Currently, I have a table on the page. Upon adding the widget, I need the table to reduce its width. ...

Internet Explorer 10 is experiencing issues with attribute binding when it comes to click events

I'm currently working on an application and I'm experiencing some issues with IE 10. The captcha text displays correctly the first time, but when I try to refresh it by clicking the button, it doesn't seem to work. My guess is that there&apo ...

I am in need of setting up two rows side by side using the display

I'm trying to have two rows side by side using display grid, but I'm facing some issues. When I use the following CSS... .grid-container { display: grid; grid-template-rows: auto auto; grid-template-columns: auto; grid-column-gap: 100px;} It cre ...

Calculate the total sum of all the span elements using jQuery

I am currently working with a more simplified calculator script that looks like this: $('input').keyup(function () { // run whenever the value changes var firstValue = parseFloat($('#first').val()) || 0; // retrieve field value var sec ...

Border concealed by Bootstrap Glyphicons

Is there a reason why glyphicons hide a border of a floated container? Can anyone shed light on this issue and suggest a workaround? Check out this link for more information. https://i.sstatic.net/CXZSd.jpg My setup: OS X 10.11.1, Chrome 47.0.2526.73 (6 ...

What is the best way to conditionally enclose an item with a link in AngularJS?

I am dealing with individuals who have a name and an optional homepage. How can I choose to wrap their name in an anchor tag? <ul ng-repeat='person in people'> <li> <a href="{{person.website}}"> {{person.name}} ...

The Jquery Text Function Exhibits Limited Functionality After Two Uses

Having some trouble with this script - it seems to only work correctly twice. The idea is to enter a city name in the text box, submit it, and then trigger a function. However, for some reason it only works two times. $("#b").click(function() { var p ...

"ReactPaginate's Dual Paginator feature for both Top and Bottom navigation

Dealing with Pagination: const CarsSection = () => { const itemsPerPage = 8; const [itemOffset, setItemOffset] = useState(0); const endOffset = itemOffset + itemsPerPage; const currentItems = carsData.slice(itemOffset, endOffset); const pageCo ...

Issues with Input-group-Addon functionality in Bootstrap 4

During my current JavaScript course project using Bootstrap 4, I encountered an issue with the input-group-addon class on a span element. The icon is not displaying as shown in the tutorial. <!doctype html> <html lang="en"> <head&g ...

Is there a way for me to update the placeholder text in my script from "CHANGE ME

Can anyone help me troubleshoot this code that's not working on my computer? I have a paragraph with the text CHANGE ME inside an element with the id "warning". I want to update this text when the login button is clicked, but it doesn't seem to ...

Sending post forms securely using HTTPS instead of HTTP

Here is the code snippet located on : <form id="MainForm" name="MainForm" method="post" action="xyz.aspx"> We now want to redirect the user to . However, we are unable to use the full URL as we need to implement the same code across all environment ...

Which IDE is the top choice for HTML5 when programming with .NET on the server side?

Is Visual Studio 2010's support for JavaScript and jQuery enough to make it a top choice for working with JS/HTML5? Or are there other IDEs out there that offer better options? I typically use .Net for the server side of my projects, so Visual Studio ...

Tips for customizing and removing single entries in a CRUD application

I am currently working on developing a CRUD app, but I am facing challenges in editing and deleting individual items. In my implementation, I have two <a> tags within a <span> tag for each created item - one for editing and one for deletion. Ho ...

Offspring element overrides styling of its parent

#popBox{ width:100%; height:100%; position:fixed; left:0; top:0; border-collapse:collapse; background:black; opacity:0.8; display:none; } <table id="popBox"> <tr> <td></td> <td></td> ...

Tips on ensuring that a span element is positioned at the bottom of a table cell

Is there a way to position the span element at the bottom of a table cell in HTML: Here is the code snippet I'm working with: <td> <span class='cat-otsikko'>Product title</span> <span class='cat-hinta&apos ...

What is the proper way to safely escape a JSON string for an object that contains user-generated content?

How can I correctly use the variable s for the value-field of an option-element while escaping user input used for key and value? var key='highway'; var value='track'; var s = JSON.stringfy({ [key]:value }, undefined,''); s ...

Is there a way to eliminate the fading effect of the modal-backdrop in Bootstrap?

I am looking to present the user with a sequence of modals, rather than just one. The idea is to have the initial modal fade in with a backdrop, and keep the backdrop visible for the subsequent modals without the fading effect. The backdrop should only fad ...

Using the Table-multiple-sort feature in boostrap-table is not functioning properly when there are multiple tables present on a single page

I have implemented bootstrap-table along with the extension table-multiple-sort. The issue I am facing is when I include two tables on a single page (with the second table within a modal window), the multisort feature does not seem to work on the second ta ...

Numerous pop-up windows on a single webpage

I am facing an issue with two modal windows on the same page. When I click on the button with the attribute: data-target='#change', the CHANGE MODAL WINDOW fails to show up. As I lack experience in JavaScript, could the problem be with the follo ...

When trying to open an HTML table that was exported to .xls file using FireFox for downloading, it fails

I have been utilizing a function that was sourced from stackoverflow. It functions correctly on Internet Explorer and Google Chrome, however, on FireFox, the downloaded file cannot be opened in Excel. When attempting to open the file in Excel, it shows up ...