Is there a way to make all Bootstrap column heights equal using only jQuery?

I am currently working on matching the heights of two columns without using an existing library like match-height.js. In this specific case, I have a row with 2 columns where the first column contains a centered black square and the second column contains a heading and paragraph. My goal is to ensure that the columns with the class "about-wrapper" have equal heights.

Here is the HTML structure:

<div class="container-fluid" id="about-section">
    <div class="row">

        <div class="col-md-4 about-wrapper" id="about-logo-wrapper">
            <div id="about-logo"></div>
        </div>

        <div class="col-md-8 about-wrapper" id="about-text-wrapper">
            <h2 class="main-heading" id="about-heading"> ABOUT THE CEO </h2>
            <p class="main-body" id="about-body">
                Paragraph content goes here...
            </p>
        </div>


    </div>
</div>

And here is the CSS styling for the logo section:

#about-logo-wrapper {
    display: flex;
    justify-content: center;
    padding: 0px;
    margin-bottom: 50px;
    border: 3px solid red;
}

#about-logo {
    height: 200px;
    width: 200px;
    max-width: 300px;
    background: black;
    margin: 0px auto;
    align-self: center;
}

Lastly, we use jQuery to dynamically set the height of the logo wrapper equal to the height of the text wrapper:

$(document).ready(function(){
    $("#about-logo-wrapper").height = $("#about-text-wrapper").height;
});

Answer №1

You seem to have misunderstood the usage of the height() method. Remember, it's a function and not just a property. Make sure you provide a parameter when trying to set the height...

$(document).ready(function(){
    $("#banner").height($("#content").height());
});

For more detailed information, refer to the official documentation...

http://api.jquery.com/height/

Answer №2

To determine the greater height between the left and right cells, you can use this code:

var h = $("#about-text-wrapper").height() > $("#about-logo-wrapper").height() ? 
        $("#about-text-wrapper").height() : 
        $("#about-logo-wrapper").height();

Next, set this height to the about-wrapper:

$(".about-wrapper").height(h);

You can view the snippet in full page mode here:

var h = $("#about-text-wrapper").height() > $("#about-logo-wrapper").height() ? $("#about-text-wrapper").height() : $("#about-logo-wrapper").height();

$(".about-wrapper").height(h);
#about-logo-wrapper {
    display: flex;
    justify-content: center;
    padding: 0px;
    margin-bottom: 50px;
    border: 3px solid red;
}

#about-logo {
    height: 200px;
    width: 200px;
    max-width: 300px;
    background: black;
    margin: 0px auto;
    align-self: center;
}
#about-text-wrapper {
    border: 3px solid green;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid" id="about-section">
    <div class="row">

        <div class="col-md-4 about-wrapper" id="about-logo-wrapper">
            <div id="about-logo"></div>
        </div>

        <div class="col-md-8 about-wrapper" id="about-text-wrapper">
            <h2 class="main-heading" id="about-heading"> ABOUT THE CEO </h2>
            <p class="main-body" id="about-body">
                Paragraph content goes here...
            </p>
           <h2 class="main-heading" id="about-heading"> ABOUT THE CEO </h2>
            <p class="main-body" id="about-body">
                Paragraph content goes here...
            </p>
           <h2 class="main-heading" id="about-heading"> ABOUT THE CEO </h2>
            <p class="main-body" id="about-body">
                Paragraph content goes here...
            </p>
        </div>


    </div>
</div>
CSS:

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

Scrollbar Excess in Windows 10 on Chrome Version 76

<div style="overflow-x: hidden"> <div style="height: 100%"> <p style="margin-bottom: 1rem"> lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan nisl id maximus gravida. </p> ...

Issue with QuickSand Script not displaying properly on Internet Explorer 7

My website features an edited version of Quicksand that displays correctly on Chrome, Opera, and Firefox, but runs into CSS issues on IE. Oddly enough, when I was using the static version, the CSS displayed properly even on IE until I added the Quicksand e ...

Demonstrating various elements within an application using Vue3

I created two components and attempted to display them in a Vue 3 application. Here is my HTML code: <div id="app"> <image_preview> URL: [[image]] </image_preview> <file_uploader> Counter:[[coun ...

How can I insert my JavaScript functions into the JSF event queue for processing?

Is there a way to tap into the default JSF ajax(JS) event queuing system in order to execute events sequentially? I am attempting to align my JS events with this queue. Is there a global variable that can facilitate this synchronization? ...

Having trouble with my Bootstrap 4 navbar button - what am I doing wrong?

After conducting research online, I found myself unable to resolve my issue due to my lack of proficiency in English. I apologize for any confusion caused and would like to revisit the topic. The problem lies with my navbar toggle that is not functioning ...

The dichotomy between public and private methods within a Vue.js component

Within a component, I have two functions defined. One is foo(), which is defined within <script>, and the other is fooExported(), which is defined in the body of export default {}. My understanding is that functions inside export default {} can be a ...

Is it possible to apply the same styling to multiple elements simultaneously in jQuery by grouping them as in CSS?

Keeping code neat is essential. In CSS, elements can be grouped like this: .element1, .element2, .element3, .element4, .element5, .element6 { font-weight:bold; } I am curious if there is a similar method in jQuery or if each element needs to be set indi ...

What is the reason why setting 'onClick' as an event handler is not flagged as a syntax error?

I am currently working on a JavaScript code snippet where I am trying to change the headline text when it is clicked. The code I have written is: var headline = document.getElementById("mainHeading"); headline.onClick = function() { headline.innerHTML ...

What is the best method to update numerous low-resolution image sources with higher resolution images once they have finished loading?

I'm currently developing a website that implements a strategy of loading low-resolution images first, and then swapping them for high-resolution versions once they are fully loaded. By doing this, we aim to speed up the initial loading time by display ...

Utilizing AngularJS for Your Business Website

We are in the process of developing a new commercial website to replace our current one. Concerns about performance are on our minds. The amount of data we have per page is not very heavy, with a maximum of 150 data binds. We plan to use AngularJS 1.2 t ...

AngularJS's $http.get function has the ability to read text files, but it struggles with reading JSON

I'm new to angularjs and I am struggling to retrieve data from a json file using the $http.get method. It seems to work fine when I try to read a simple txt file, but not with the json file. I can't seem to pinpoint where the issue lies... Belo ...

Allow only specified tags in the react-html-parser white list

Recently, I've been working on adding a comments feature to my projects and have come across an interesting challenge with mentioning users. When creating a link to the user's profile and parsing it using React HTML parser, I realized that there ...

Guide to continuously play the animation, Version 2

I have been struggling with an animation that I need to loop indefinitely. The problem arises when trying to use animation-iteration-count: infinite. It seems like no matter where I place it in the code, whether within the keyframes or normal CSS rules, it ...

Updating an event listener during the $(document).ready() function and handling ajax requests

In my Rails 4 application, there is an event listener that I have repeated in three different places. The event listener looks like this: $('.remove-tag-button').on('click', function () { $.ajax({ type: "POST", data: {i ...

Problem concerning the window object in a React functional component

Hey there, I am currently facing a situation where I need to access the window object within my React component in order to retrieve some information from the query string. Here is an excerpt of what my component code looks like: export function MyCompone ...

Using jsPlumb to Access an Element After a "Mouseup" Event has Completed

$(document).on('mouseup', '.agent-wrapper', function(info){ console.log(info); // Everything is working fine console.log(this); }); .agent-wrapper represents an element-wrapper for all jsPlumb objects. $(document).on(' ...

Transferring a multidimensional array from a controller in CodeIgniter to DataTables using jQuery

Is there a way to pass a multi-dimensional array from the controller into dataTables? While using CodeIgniter and jQuery dataTables, I encountered no issues when working with just a single array. However, when attempting to use a 2D array, the data does n ...

Issues with jQuery draggable functionality in Ruby on Rails 3.1

I created a new RoR 3.1 project to experiment with this feature. To enable draggable functionality, I included the necessary jQuery .js files in my app/assets/javascripts directory: jquery.ui.core.js jquery.ui.widget.js jquery.ui.mouse.js jquery.ui.dragga ...

Please refresh the page after acknowledging the error

I am facing an issue with my PHP page that triggers a javascript alert upon encountering an error. if (strpos($this->color,':') !== false) { echo '<script type="text/javascript">alert("Please use the RBG format of 255:2 ...

Exploring the keyof operator in Typescript for object types

Is there a way to extract keys of type A and transfer them to type B? Even though I anticipate type B to be "x", it seems to also include "undefined". Why does the keyof operator incorporate undefined in the resulting type? It's perplexing. I kn ...