Is there a way to adjust the height of one div based on the height of another div in Bootstrap?

I am experimenting with a Bootstrap example featuring a table in the left column and 4 columns in 2 rows in the right column. Check out the code below:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<body>
<div class="container-fluid">
<div class="row">
<div class="col-lg-6" style="background-color:lavender">
<p>Table with hover, striping, borders, context</p>            
  <table class="table table-hover table-striped table-bordered">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Default</td>
        <td>Defaultson</td>
        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4a0a1a284b7aba9a1a9a5ada8eaa7aba9">[email protected]</a></td>
      </tr>      
      <tr class="table-primary">
        <td>Primary</td>
        <td>Joe</td>
        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ef4f1fbdefbe6fff3eef2fbb0fdf1f3">[email protected]</a></td>
      </tr>
      <tr class="table-primary">
        <td>Primary</td>
        <td>Joe</td>
        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f59f9a90b5908d9498859990db969a98">[email protected]</a></td>
      </tr>
    </tbody>
  </table>
</div>
<div class="col-lg-6">
<div class="row">
<div class="col-md-6" style="background-color:lavenderblush">
<p>Some text</p>
</div>
<div class="col-md-6" style="background-color:lavender;">
<p>Some text</p>
</div>
  </div>
  <div class="row">
<div class="col-md-6" style="background-color:lavender">
<p>Some text</p>
</div>
<div class="col-md-6" style="background-color:lavenderblush;">
<p>Some text</p>
</div>
  </div>
  </div>
</div>
</div>
</body>

As seen in the image below: https://i.sstatic.net/QP1K4.png The left column's height adjusts automatically with the table height. However, the right column does not adjust its height according to the left column. I want the right column's height to be relative to the left column's height, splitting evenly into 2 stacked columns and adjusting automatically with the left column's width. For instance, if the table has more rows, the left column's height increases, and the right column's height should increase as well, remaining at 50% of the left column's height. This would result in a layout like the one shown in the image below:

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

Answer №1

In order to achieve the desired layout, it is recommended to utilize flexbox properties. While it may be tempting to add flexbox settings to Bootstrap's row and col-, this approach is considered a poor practice. It is advisable to create new elements and avoid customizing the CSS of Bootstrap grid elements unless necessary for extension purposes.

Upon testing, it was observed that the second col- maintains the correct height, but its children (the .row) do not. To address this issue, convert the second col- into a flexbox element to allow its children to inherit its height. Subsequently, adjust the children (now flexbox items) to grow equally. However, caution is advised as modifying Bootstrap components directly may lead to conflicts with their predefined properties.

TL:DR: Apply display:flexbox to the second col-xx-x and expand the .row within using flex-grow:1. It is essential to conduct further analysis for optimal code standards.

View the code demonstration on Codepen

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

The art of perfect alignment: Mastering the positioning of Material-UI Grid

This issue has been resolved Hey there, I'm currently working on a React App with Material-UI and I'm trying to center a Grid item that includes a Card along with two additional Grid items. Below is the relevant code snippet. Although the Cards ...

GraphQL query excluding empty fields for various types of objects

Utilizing Apollo Graphql, I attempted to employ inheritance for retrieving various types of models without success. My goal is to extract specific fields from the objects while omitting those that are unnecessary. To address the issue of incomplete object ...

Creating a webpage that dynamically loads both content and video using HTML and Javascript

I designed a loading page for my website, but I could use some assistance. The loading page remains visible until the entire HTML content is loaded and then it fades out. However, I am facing an issue because I have a background video that I want to load ...

Add a flexible element to a container without disrupting the alignment of the other

I'm facing a challenge in adding an action button to the end of a grid layout without affecting the centering of the items. The button should seamlessly fit into the grid, just slightly offset. If you check out my demo, you'll see what I mean. ...

Mobile devices not showing the Navbar bootstrap menu

My header.php works perfectly on desktop, but the navigation bar is not displaying properly on mobile devices. Here is my code: <!DOCTYPE html> <html> <head> <title>International Pvt. Ltd.</title> <meta name="viewpo ...

`initMap` does not exist as a function

Hey everyone, I need some help: I recently integrated the Google Maps API into my AngularJs project and encountered an error in the console: Uncaught message: "initMap is not a function" name: "InvalidValueError" This occurs when the Google Map API is ...

What steps can be taken to resolve the error "Incompatible types: TodoItem undefined cannot be assigned to type TodoItem"?

I am currently in the process of learning TypeScript. Here is what's inside todoItem.ts: export class TodoItem { constructor( public id: number, public task: string, public complete: boolean = false ) {} printDetails(): void { ...

Utilize the entire width for header elements

I have implemented four header elements: home, about, portfolio, and contact. I want these elements to stretch across the entire navigation bar with each taking up 25% of the space. How can I achieve this? Additionally, I specified that the home element sh ...

Using ngModel instead of value to bind a custom Angular directive for currency input

Currently, I am using a specialized mat-input-currency format directive to automatically convert my field inputs into currency. You can find the npm repository here. However, the directive binds the element data to [value] of the input, and I require it t ...

Prevent validation on a particular input field with JQuery validator and Bootstrap

Is there a way to use JQuery validator to validate an entire form except for a specific input? Here is an example code snippet showing how this can be done: jQuery.validator.setDefaults({ debug: true, success: "valid" }); ...

CSS animation using a series of linked elements

Is there a way to make my buttons animate sequentially? For example, the second button should start animating only after the first one has finished. Any assistance would be greatly appreciated! a { padding: 6px; display: block; width: 50px ...

Share your Facebook link with dynamic parameters

When attempting to create a share URL with GET parameters, I am encountering some issues with double encoding. <a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.bing.com%2Fsearch%3Fq%3Dkeyword" /> This results in a faulty URL, while &l ...

Struggling to configure an onClick handler in Next.js

Unexpectedly, I was met with a surprise while trying to access react.dev, as it stated that create-react-app is no longer recommended for bootstrapping React applications. No worries, the world is always evolving. Let's explore Next.js for my first p ...

Assigning controller variables within an ajax request

I'm new to AngularJS and I have a question about controller attributes. I've created an attribute called 'anuncio', which contains an array of objects as shown below: var anuncioModule = angular.module('anuncioModule',[]); a ...

The method .setArray has been deprecated in THREE.BufferAttribute. Instead, please use BufferGeometry .setAttribute for unindexed BufferGeometry operations

Seeking assistance with updating the webgl-wireframes library code to the latest version of threejs. The current function is generating the following errors: Uncaught TypeError: THREE.Geometry is not a constructor THREE.BufferAttribute: .setArray has ...

Tips on dividing and recycling mongodb connection in Node.js

I am currently troubleshooting the connection to MongoDB using Node.js. The code I have in a file named mongodb.js is as follows: const mongoClient = require('mongodb').MongoClient; const env = process.env.NODE_ENV || 'development'; co ...

Issue with ThemeManager in Material UI & React: Constructor is not valid

Currently, I am integrating Material UI into a small React application, but I suspect that the tutorial I am following is outdated and relies on an older version of Material UI. The error _materialUi2.default.Styles.ThemeManager is not a constructor keeps ...

Trouble with data binding in AngularJS when using the input element

I am encountering an issue with my AngularJS code. When I try to input text into the textbox, it is not appearing in the binding. <!DOCTYPE html> <html lang="en"> <head> <script src="js/angular.js"></script> <scr ...

I am currently running a recursive loop to fetch data from MongoDB. However, the Express.js function runs through the entire script before the data can be successfully returned

Can someone assist me with setting up my Express route to handle the return of data from a recursive function that involves promises and fetching MongoDB data? Currently, my route is executing immediately without sending the data back to the client. The da ...

Can html-webpack-plugin be configured to create <style> elements from CSS files?

I am managing a static site with Vue and Webpack. In my project, I have a file named style.css containing global CSS rules which I import using import './styles.css' in my index.js file. Additionally, I have some .vue files that generate their o ...