Dealing with uneven column heights using Bootstrap 4's Flex feature

Currently, I am using Bootstrap 4 to create a simple 4*4 grid of divs that contain an image and some text. Initially, I tried using 6 columns nested inside a single row, but the picture wasn't centered correctly within the column. Then, I applied text-center to the row, which centered the image but also centered the text when I wanted it to be aligned to the left of the image.

After scrapping the rows and columns approach, I attempted using Bootstrap's flex classes. The structure looked like this:

<div class="d-flex justify-content-around">
    <div class="d-flex flex-column">
        <div> image and text content here </div>
    </div>
</div>

While this new method worked well, the varying column heights caused alignment issues in the overall layout:

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

I'm now looking for a solution to fix this issue. What is the best practice for creating a grid of divs like this using Bootstrap 4?

For reference, here is the full code snippet:

<div class="row border justify-content-around border-r flex-wrap">
                    <div class="d-flex flex-column border-r"> <!-- this is repeated twice more for each column -->
                        <div class="tile">
                            <a href="./wanderlust.html">
                                <img class ="thumbnail img-fluid" src ="images/wanderlust.jpg"/>
                                <h5 class=" thumbnail-title"> Wanderlust </h5>
                                <p class=" thumbnail-subtitle"> design research + UX + UI <br> +  programming </p>
                            </a>
                        </div>
                        <div class="tile">
                            <a href ="behavior-change.html">
                                <img class ="thumbnail img-fluid" src ="images/breakfast.jpg">
                                <h5 class="thumbnail-title"> Behavior Change </h5>
                                <p class="thumbnail-subtitle"> design research</p>
                            </a>
                        </div>
                    </div>
</div>

Answer №1

To center align images within columns, utilize the row and col-* classes along with the d-block and mx-auto classes.

<img class="thumbnail img-fluid d-block mx-auto" src="images/wanderlust.jpg" />

The d-block class changes the display of an element to block, while mx-auto adjusts the margins to center the image horizontally within the column.

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

What is the best way to open just a single detail in a b-table?

When the button is clicked, the row details are opened. To ensure that only one line detail remains open at a time, I want any previously open details to be closed when another one is opened. view sample screenshot If you look at the example provided, mu ...

Checking Whether a Value Entered in an Input Field Exists in an Array Using jQuery

Can someone help me with checking if a specific value is in my array? I want to achieve something like that, any suggestions on how to do it? if(jQuery.inArray($('#ValueInputTitle').val, variableValueInput) !== -1) { console.log("is in arr ...

Issues with web display on Android devices

My website is having display issues specifically on Samsung and Motorola devices, even when using different browsers. It seems that the area using transform CSS is breaking apart. You can view my website at I've tried several fixes but nothing seems ...

Proper Placement of Required Field Validator Messages

I am having an issue with the validation text appearing behind my textbox instead of below it. Despite setting the display to block in the CSS class for the assignment type and start date, the validation text is not displaying properly. I have tried variou ...

The size of <dropdown lists> in Safari 5.0.5 for Windows

While developing a web form, everything seemed to work perfectly in Firefox 4 and 3.6, Chromium 11, Opera 11.10, and IE 8. However, in Safari 5.0.5 for Windows, all <select> elements appear wider, causing the layout to break. A comparison screenshot ...

Activate hover effect on iOS by tapping, not clicking

For the longest time, I believed that the hover effect on iOS devices only appeared when a complete "click" or "touch" occurred. However, my perspective changed when I came across this page: On this page, the hover effect is triggered simply by tapping on ...

Enhance the appearance of tables in asp.net core razor using Bootstrap Group By V2 while also customizing

I have incorporated the Bootstrap Group By V2 extension into my asp.net core razor application to hide certain table columns using the hidden property: <td hidden="@Model.IsHidden"> @Html.DisplayFor(model ...

Preserve the active class position even after the page is refreshed using JavaScript

Utilizing the Flickity plugin, I have successfully created a tab-based content carousel. By incorporating the hash script available on GitHub, users can directly access a specific tab using URLs like example.com/#slide-1. However, I am facing an issue whe ...

What is the correct way to write the syntax for wp_register_style function in

I'm attempting to include a cache-buster version in my CSS file. The guides mention: <?php wp_register_style( $handle, $src, $deps, $ver, $media ); ?> However, I've scoured Google and Stack Overflow for the correct formatting of these var ...

CSS - when "start" is not 1, an alternative to the "nth-child" selector

Imagine a scenario where you have a list of questions that start at 0 and you want to apply CSS styling based on their value. For instance, consider the following list... <b>How are you feeling?</b> <ol start="0"> <li>Great< ...

Applying media queries to incorrect screen sizes

My media query seems to be behaving oddly. @media only screen and (max-width: 1200px) { .tool-panel { margin: 0px 24px 0px 0px; } } It is getting applied at 1183.20px instead of 1200px. This discrepancy is consistent across all browsers ev ...

Customizing Your Keyboard Design with CSS

I need assistance in creating a compact and dynamic keyboard layout with characters only, but I have hit a roadblock. Here is the link to my current progress: http://jsfiddle.net/45zDd The design is almost complete, however, the second and third rows req ...

Utilizing the active tab feature within CSS

I am currently working with a detailed structure of bootstrap theme classes. Currently, I am in the process of designing a menu. This is the code snippet for the navigation bar design in Bootstrap- <div class="navbar navbar-fixed-top navbar-invers ...

Why is my D3 map not positioning at the center of the page?

Having trouble with centering my D3 map on the webpage. The CSS doesn't seem to apply correctly even though I've tried adding margins to the map class. I'm not sure why the applied CSS isn't working as expected. Could there be somethin ...

Utilizing ng-class with Boolean values in AngularJS

On my page, I have a pair of buttons that control the visibility of elements using ng-hide and ng-show. <a ng-click="showimage=true" ng-class="{ 'activated': showimage}" class="button">Images</a> <a ng-click="showimage=false" ng-c ...

How come the Bootstrap 4 row doesn't stretch to the entire available width?

It seems that flexbox should fill all available space in width, but for some reason, the row I inspected is not doing so. Even though it's set to display flex and there doesn't seem to be anything unusual about it, Chrome indicates that there is ...

Safari CSS issue: Relative parent and child with pseudo selector not producing consistent output across different browsers

I'm not seeking a specific fix for the code, but rather an explanation as to why it behaves this way. In Safari, children elements with a relative parent appear in a different position compared to other browsers. Changing the child to absolute positi ...

Can CSS be used to create an animation effect with just this image?

Is it possible to incorporate a running image of "Pikachu" using CSS instead of creating a heavier GIF format? I have the image link and code below, but need assistance on how to implement it. Can you provide guidance? image: .pikaqiu_run { width: ...

What is the process for printing the CSS stylesheet for PPI::HTML highlight?

PPI::HTML has done an impressive job of formatting the HTML highlighting for my Perl code, similar to the example on CPAN. However, I am facing challenges in making the output usable without the appropriate CSS styles. Unfortunately, I am unsure of how to ...

Issues encountered with VueJS Bootstrap implementation include failure to load app.scss properly as well as problems with the dismissable b-alert button displaying as a square with an "x" in the center

I am facing some difficulties while incorporating Bootstrap into my Vue.js project for the first time. Following the instructions provided here, I added everything step by step until I reached the point where I had to create app.scss. Placing it in the as ...