Tips for aligning row content in the middle of a container div with bootstrap

For my Web Development course assignment, I am using css, html, and bootstrap to create a website. However, I am facing some layout issues with the bootstrap cards within container and row div. The problem is that the cards in each row are not aligned at the center of the column, resulting in some empty space on the right side of the col. You can see the issue in this screenshot.

Here is the code snippet causing the alignment issue:

<div class="container">

    <div class="row ">

        <div class="col-4">
            <div class="card text-center " style="width: 18rem;">
                <img src="imgs\products\cameras\1.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">Canon EOS Rebel T7</h5>
                    <p class="card-text">Price : Rs. 37000.00</p>
                    <a href="#" class="btn btn-primary btn-block">Add to cart</a>
                </div>
            </div>
        </div>    

        <div class="col-4">
            <div class="card text-center" style="width: 18rem;">
                <img src="imgs\products\cameras\2.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">Fujifilm X-T3</h5>
                    <p class="card-text">Price : Rs. 34000.00</p>
                    <a href="#" class="btn btn-primary btn-block">Add to cart</a>
                </div>
            </div>
        </div>

        <div class="col-4">
            <div class="card text-center" style="width: 18rem;">
                <img src="imgs\products\cameras\3.jpg" class="card-img-top" alt="...">
                <div class="card-body">
                    <h5 class="card-title">Nikon D5600</h5>
                    <p class="card-text">Price : Rs. 43000.00</p>
                    <a href="#" class="btn btn-primary btn-block">Add to cart</a>
                </div>
            </div>
        </div>

    </div>
</div>

I am looking for a solution to center align the cards in the column using CSS or Bootstrap. Additionally, I would like to make all the cards the same size (width and height) regardless of the different image sizes inside them. As shown in the screenshot, the last two cards have varying sizes due to different image dimensions.

Answer №1

Regarding your initial inquiry:

To center the card within your column, simply add

col-4 d-flex justify-content-center
to your column definition. This adjustment will ensure that the card is aligned in the middle of the column, as illustrated here. In this visual representation, blue denotes the container, purple signifies the column, and green highlights the card.

We hope this solution proves effective for you!

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

Deactivate while maintaining menu options

Currently, I have a Vue.js form that manages adding and updating data for patients. The issue at hand involves a <select> tag which allows for the addition of a relative. This select field is populated by an array called PPrelations, which is sourced ...

Switching the orientation of an iPhone on Chrome can lead to content being cut off

Currently, I am conducting testing on an iPhone XS running iOS 15.6.1 The website seems to function properly on iOS Safari (although untested on Android), however, a problem arises when using Chrome and rotating the screen from landscape to portrait mode. ...

When an option is selected in one dropdown, a list is dynamically populated in another dropdown. However, the entire column then displays the selected row's options in a table format

https://i.stack.imgur.com/q7tMT.png Upon selecting an option from a dropdown within a table row, I make a call to an API to fetch a list of strings into another dropdown field for that specific row. However, the entire column is being populated with that r ...

Tips on how to loop a song continuously in jPlayer's circular mode

Can you help me figure out how to make a song repeat in jPlayer circle? I have the code for autoplay, but I also want to add a repeat functionality. I tried adding options like repeat:, but it didn't work as expected. <script type="text/javascript ...

The responsive functionality in Bootstrap is failing to work properly when I resize the browser

I am just starting to learn about bootstrap and I'm facing a challenge with converting a static page into a responsive design. The original width of the page is 980px, so I tried creating bootstrap columns based on the design and applied CSS to correc ...

The text does not change in the input field even with the .value method

I'm encountering an issue where I want to use .value to set the text of an input field. However, after setting the value of the input field, the text disappears when clicked on. I would like to find a solution where the text does not disappear upon cl ...

Unable to execute a JavaScript function when triggered from an HTML form

This is the code for a text conversion tool in HTML: <html> <head> <title> Text Conversion Tool </title> <script type="text/javascript"> function testResults(form) { var str = form.stringn.value; var strArray = str.split(" ...

Learn the effective way to customize the primary button text color in Bootstrap 4 using SCSS styling

Looking to customize the .btn-primary text color. I attempted to modify the background color in _variables.scss by adding the following line: $primary: #a1c1b6; However, I was unable to change the text color despite trying various options. // not working ...

Display Binary Image in HTML Table using Server-side Code

I am currently working on creating a table that will retrieve binary image data from a database and display it in an HTML table. Here is the markup I have used: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml1 ...

Bootstrap Table with Numerous Rows and Columns

I am striving to create a table layout similar to the one shown in the image using bootstrap 5. https://i.sstatic.net/lEnYX.png My attempt so far looks like this <table class="table table-bordered"> <thead> <tr> ...

Tips for adjusting the size and position of these div containers

My Steam Inventory Viewer is experiencing an issue with items with longer names. The div container becomes bigger than others, as seen in the demo on freegamekeys.info/trade or the image at http://prntscr.com/crpqk5. I am having trouble explaining my probl ...

Desktop sharing in HTML5/H.264 format for optimal performance and compatibility across all

Looking to showcase my desktop through live streaming over http to multiple users. The initial plan is to provide a real-time read-only view of the desktop for various users. In the future, we may consider granting users access to control the desktop using ...

A groundbreaking algorithm engineered to launch a sequence of distinct hyperlinks upon each button press

I have a unique script that allows me to open links randomly, but now I want to create a new script that opens links sequentially and goes back to the initial one. For example, clicking a button will open link1, then clicking it again will open link2, an ...

Eliminate HTML inserted into Selector

My approach to handling validator errors involves injecting HTML next to the incorrect content, which is then displayed correctly when clicked. However, I am facing challenges in removing the injected HTML once the bad data is corrected. Despite trying var ...

An illustration of the fundamental concepts of require.js

main.md <markdown> <head> <script data-main="script" src="http://requirejs.org/docs/release/2.1.8/minified/require.js"></script> </head> <body></body> </markdown> script.css defi ...

Redirection in Django to a view located outside the current app

I need assistance with my Django project's app called users. When logging into users/login.html, I want it to redirect to the URL /home.html Here is how my templates are structured: --> users | .....-->login.html --> base.html --> home. ...

Problem with overlapping numbers in the Vis network

I am currently working on a project using Angular 8 and Visnetwork. Everything is going well, but I am facing an issue with overlapping numbers on lines. Is there a way to adjust the position of the numbers on one line without separating the lines? Can s ...

Enhancing productivity with a more streamlined process for creating a responsive website design through the optimization of

I recently had the task of placing two images in a band on a webpage and ensuring they were responsive to different screen sizes. Image 'a' represented a circular logo, while image 'b' was a rectangular logo. The red band served as the ...

Is there a way to place an image in front of every item in an inline list?

I am working on creating an inline list that shows an image before each list item. However, I am facing an issue where the image appears above the list item instead of being on the same line. My goal is to have the image displayed to the left of each item ...

Navigating a Bootstrap modal using arrow keys for scrolling - up and down

I attempted to address this issue by using the following code: // here, 'this' represents the modal $(this).focus(); Despite trying the above solution and even attempting to trigger a click event on it, I was unable to get it to work! UPDATE ...