How do I resolve the problem of Bootstrap column heights? Setting columns to have an automatic height in Bootstrap grid

Currently working on a website and encountering an issue that needs to be resolved. I have included some reference photos below to illustrate the problem:

We are getting this We want this.

Thank you in advance for your help.

When attempting to set the height to auto, the results are inconsistent. Below is the code snippet:

<div class="row">
    <div class="col-lg-3">
        Content
        Content
        Content
        Content
    </div>
    <div class="col-lg-3">
        Content
        Content
    </div>
    <div class="col-lg-3">
        Content
        Content
        Content
    </div>
    <div class="col-lg-3">
        Content
    </div>
    <div class="col-lg-3">
        Content
        Content
        Content
        Content
        Content
    </div>
    <div class="col-lg-3">
        Content
    </div>
    <div class="col-lg-3">
        Content
        Content
        Content
    </div>
</div>

Answer №1

It's difficult to provide an exact solution without examining your source code. I recommend that you include it for better assistance.
Using triple backticks before and after a code block will display it neatly with syntax highlighting!

Based on similar issues I've encountered in the past, here's my best guess regarding the actual question:

<div class="container">
    <div class="row">
        <div class="col-6">
            <div style="height: 250px" class="card m-2 bg-primary"></div>
        </div>
        <div class="col-6">
            <div style="height: 100px" class="card m-2 bg-primary"></div>
        </div>
        <div class="col-6">
            <div style="height: 60px" class="card m-2 bg-primary"></div>
        </div>
        <div class="col-6">
            <div style="height: 200px" class="card m-2 bg-primary"></div>
        </div>
    </div>
</div>

Bootstrap uses a 12-column layout system, where each row consists of 12 equal column units that can be distributed between child columns.
In the provided code, each column is set to be 6 column units wide (col-6), making them half the width of the parent container.

The first two columns fit perfectly, but the third column overflows and needs to accommodate an overflow situation.
When a row overflows, it behaves as if a second row is created to contain the overflow:

<div class="container">
    <div class="row">
        <div class="col-6">
            <div style="height: 250px" class="card m-2 bg-primary"></div>
        </div>
        <div class="col-6">
            <div style="height: 100px" class="card m-2 bg-primary"></div>
        </div>
        <!-- End of the first row -->
        <!-- Beginning of the second row -->
        <div class="col-6">
            <div style="height: 60px" class="card m-2 bg-primary"></div>
        </div>
        <div class="col-6">
            <div style="height: 200px" class="card m-2 bg-primary"></div>
        </div>
    </div>
</div>

To resolve this issue, ensure that each column element contains all the child elements for that column:

<div class="container">
    <div class="row">
        <div class="col-6">
            <!-- Place all elements for the first column here -->
            <div style="height: 250px" class="card m-2 bg-primary"></div>
            <div style="height: 100px" class="card m-2 bg-primary"></div>
        </div>
        <div class="col-6">
            <!-- Place all elements for the second column here -->
            <div style="height: 60px" class="card m-2 bg-primary"></div>
            <div style="height: 200px" class="card m-2 bg-primary"></div>
        </div>
    </div>
</div>

The examples provided focus on two columns, but I've created a sample with four columns, available here.

For more information on the Bootstrap 4 grid system, refer to their documentation here.

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

Revolutionizing Zen Cart with slimMenu

Is there a smarter person out there who can help me understand why the slimMenu is breaking when I add these files to the bottom of the page? <link href="includes/templates/westminster_new/css/age-verification.css" rel="stylesheet"> <script src=" ...

Exploring the contrast in importing CSS between the HTML header, JS file, and Vue Component

Exploring the world of Vue with webpack, I find myself curious about the various ways to import CSS. It appears that there are three methods for importing CSS: Adding style sheets directly to HTML headers: <link type="text/css" rel="stylesheet" ... &g ...

Aligning MaterialUI Grid items vertically within various Grid containers

Looking to implement a design that features three vertical columns. The first and last columns will display MaterialUI cards, while the middle column will showcase a vertical line with dots aligned vertically with the start of each card. The height of the ...

Ways to troubleshoot the MudTabPanel during scrolling

I am trying to create a fixed text at the top of a scrollable MudTab. As I scroll down, I want the text to remain visible. Here is an example of what I have done: <MudTabs Position="Position.Top" PanelClass="pt-2" Style="hei ...

Unable to Embed Tweets resulting in 403 Error (Forbidden)

While working on embedding some Tweets on my webpage, I encountered the following error message: GET https://cdn.api.twitter.com/1/friendships/exists.json?user_a=19463349&screen_name_b=mrland_news&callback=twttr.setFriendshipExists 403 (Forbidden) ...

Arranging divs with HTML and CSS

I am currently facing issues with the positioning of 3 scripts in my HTML file. The vertical gauge is overlapping the second circular gauge, despite trying different positioning options to no avail. How can I adjust the layout so that the vertical gauge a ...

Having trouble with CSS webkit radial not working on iPad's Safari Mobile browser?

I'm feeling confused right now. I have this gradient code background-image: -webkit-radial-gradient(50% 65%, ellipse cover, #f2f2f4, #201935 55%); It's working on Safari when I change the User Agent to Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3 ...

The background image is functioning correctly, but there seems to be an issue with the image overlay

I attempted to design a profile page for my website users to have an image as a banner and their profile photo. I have achieved this: https://i.sstatic.net/kFlrQ.jpg However, when I apply the top-margin to the image, it both moves the image and expands t ...

Eliminate the cushioning on a single item

I'm currently working on a website and running into a small issue. The main page has a background with a white body in the center, containing padding for the text to prevent it from being right at the border. #content { width: 900px; overflow: h ...

The Issue with Non-Functional Links in Nivo Slider

Currently facing an issue with the Nivo Slider as it no longer links to any of the photos in the slider. Initially, I had 14 pictures linked to a post with a full embedded gallery inside. The problem arose when using a "fixed" size for the gallery, which d ...

What is the best way to ensure that custom JavaScript and CSS files in Sphinx are always loaded with the most recent changes

Within the configuration file conf.py for Sphinx, I have specified the following: html_css_files = ['css/custom.css'] html_js_files = ['js/custom.js'] However, any alterations made to custom.js or custom.css do not immediately appear i ...

Utilizing headless WordPress and React for an innovative web development approach, incorporating styles seamlessly in both the

I am looking to create a headless WordPress + React website. So far, I have successfully set up the "non-gutenberg" elements like the header and footer. Everything seems to be working fine on that front. However, I am facing an issue with the styling of t ...

Connecting CSS styles and images to my EJS templates on a distant Express server using Node.js (Ubuntu 18.04)

I have been hunting for a solution here extensively, but every attempt has failed. So, here's the issue I'm facing: I have created a basic Express server locally to display a static page until I finish full integration. The structure of my site ...

The fullscreen API allows for the creation of a full-screen element containing internal elements, while also enabling the functionality

Is it possible to utilize the fullscreen API to make any element fullscreen, even if it contains multiple internal elements, while still maintaining the functionality of dropdowns and other custom elements that may be located in different areas of the page ...

When the parent element is centered, align the children to the left

Can children be aligned to the left when the parent is aligned to the center? I have a list of elements where the parent block should be centered, but the children need to align to the left. https://i.sstatic.net/ixRxQ.jpg Now I found a solution to alig ...

How to eliminate excess white space on the right side in Bootstrap 4

Could someone please clarify why I am experiencing a white space on the right side when using Bootstrap 4? This is the primary code block for the page. <main id="intro" role="intro" class="inner text-center"> <h2>Lorem Ipsum</h2> ...

The use of the picture element, with its ability to support various image formats and sizes, must always include

Recently, I came across a VueJS template that closely resembles HTML but has the following structure: <picture> <source type="image/avif" :scrset="avif" /> <source type="image/webp" :scrset="webp" ...

Manipulating the distinct look of the final element in an *ngFor loop

I am trying to enhance the appearance of the last line of controls generated by an iterator by making it disabled and somewhat invisible. Currently, my code is functioning well, as shown below. <div *ngFor="let item of data; let last = last;"> &l ...

Adjust picture to fit in div and align vertically

JSFiddle In my fluid layout, I have a div with a required aspect ratio of 1:1. This div can contain text, an image, or both. The challenge is to vertically align the text and ensure the image fits within the div without exceeding its boundaries or losing ...

Sequence of HTML elements arranged in a stack

Recently, I came across a useful jQuery tutorial called "jQuery for Absolute Beginners: Day 8". In this tutorial, there is an interesting code snippet that caught my attention: $(function() { $('.wrap').hover(function() { $(this).childre ...