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

Proper method for calling a function within a specific scope

I am utilizing user-contributed modules that I aim to avoid editing in order to make upgrades easier. My goal is to enable users to browse for a CSV file on the local filesystem, parse it, and display it in a dynamic table. For this task, I am using PapaP ...

The form post request cannot recognize the undefined variable

When attempting to send values through an HTML form and retrieve it in console.log, I encounter an error that says "TypeError: Cannot read property 'fName' of undefined," despite declaring it in the form name. signin.html : <!doctype html> ...

Tips for inserting multiple numbers from a single row into separate options within a SELECT statement

Is there a way to create a select box with multiple options that are based on one row from my MySQL table? For example, <?php if(!empty($row['size'])) { ?> <label>Size</label> ...

Guide on reusing javascript to toggle between image sources

I have a simple website with buttons that, when clicked, change the image being displayed. However, I find myself repeating code for each button, and I'm wondering if there is a more efficient solution to this problem. Here is an example of what I cu ...

Creating components through the command line while managing multiple projects using Angular CLI 6

Currently, I am utilizing the most recent Angular CLI version (v6). Within my codebase resides a collection of applications housed within the projects directory. My objective is to create and organize various modules and components within these projects v ...

Applying CSS Styles to a Single Class Only

I have been using Zurb's Foundation to customize the navbar with my own styles, which has been successful so far. However, I encountered an issue with the responsive behavior of the navbar when the viewing container size changes. The navbar adds a sec ...

Scrolling text blocks on mobile devices

When viewing the website on a desktop, everything works perfectly. However, when accessing it on a mobile device and trying to scroll down, only the text moves while the page remains stationary. The website utilizes skrollr core for animations. I have alre ...

I'm experimenting with crafting a new color scheme using MUI, which will dynamically alter the background color of my card based on the API

I am attempting to create a function that will change the colors based on the type of Pokemon. However, I'm not sure how to go about it. Any suggestions or ideas!? Check out where I'm brainstorming this logic [This is where the color palette sh ...

Vulnerability protection against AngularJS JSON is not removed

I am currently working on an Angular app that communicates with an API. The JSON responses from the API are prefixed with )]}', as recommended in Angular's official documentation. The issue I am facing is that my browser seems to try decoding th ...

What is the best way to extract the JSON value from my API website and assign it to a new variable

Currently, I am in need of a way to convert a username into an ID. To accomplish this task, I will utilize the following API link: (where "username" is replaced by the variable name.) The main objective here is to extract the ID value from the provided li ...

The function Mediarecorder.start() is experiencing issues on Firefox for Android and is not functioning

Recently, I've been facing a peculiar issue while developing a web application. The purpose of this app is to capture about 10 seconds of video intermittently from the device webcam and then upload it to a server. For this functionality, I utilized th ...

The variables $invalid and $valid in my AngularJS form have not been assigned any values

I came across a post on StackOverflow discussing the issue of both "myForm.$valid" and "myForm.$invalid" being undefined on an Angular form. However, my problem is slightly different. I have defined a form like this: <form name="EntityForm" role="form ...

Is the unit-converts npm package compatible with the website https://unpkg.com?

Having issues importing the npm package 'convert-units' using unpkg, I attempted the following method: <script src="unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="02616d6c746770762f776c6b767142302c31 ...

Looking to change the date format from 24/05/2021 to 24/May/2021 using jQuery or JavaScript?

My client prefers not to use a date picker, but wants to be able to type dates directly into a textbox and have them automatically converted to the format 24/May/2021 as they leave the field. I am looking for a solution using either Javascript or jQuery. ...

ui-jq flot graph with lazy loading

I am working with this HTML code: <div id="test" ui-jq="plot" ui-options=" [ { data: {{line}}, points: { show: true, radius: 6}, splines: { show: true, tension: 0.45, lineWidth: 5, fill: 0 }, label: 'Akademi' }, ], { ...

Notification does not appear once the full content of all iframes on the page has been loaded

<!DOCTYPE html> <html lang="en"> <head> <title> </title> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="css/custom.css" /> </head> <bo ...

What is causing .attr('title') to retrieve the title of the element before?

UPDATE Flexslider now includes several callback spaces for use, making this functionality possible. after: function(){}, //Callback: function(slider) - Fires after each slider animation completes Thank you to everyone who contributed! LIVE CO ...

Customizing CSS for Various Browser Sizes

I have a query regarding window-dependent CSS. It seems to be a common issue, but I am facing some difficulties with it on Wordpress. I am currently using the script recommended by Nettuts. My goal is to apply different CSS styles based on the user's ...

Can a webpage have a fixed focus point that automatically adjusts the scroll bar when the content changes?

Looking for some assistance with a message board issue I am facing. As new messages are added, the board constantly expands and pushes older ones down. Is there a way to lock the scroll to a specific message? For example, keeping the same view of message ...

Problem with alternating row colors in my table

Trying to add some style to my table on the webpage by alternating row colors, but I'm running into some issues. I've followed tutorials and tried using different CSS selectors like nth-of-type(even), nth-of-type(2n+0), and nth-of-type(odd). Howe ...