How can I make a div take up the entire height of its parent column using Bootstrap?

I need the div with the red border to match the height of the green div on the right. I'm using Bootstrap 4 for this layout!

I've experimented with display: flex and flex-grow, and also tried placing the border on the column (which achieves the desired effect but loses the padding).

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" >
<div class="container-fluid">
  <div class="row">
    <div class="col-12 col-lg-6 order-lg-1">
      <div class="border border-lg border-success p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium">This is an example sentence. It may go on for a couple of lines just to see what's going to happen!</div>
    </div>
    <div class="col-12 col-lg-6 order-lg-3">
      <div class="text-xlarge text-success mt-2"><i class="icon icon-md line-height-1">check</i> Correct</div>
      <p class="mb-3 mb-lg-0 text-large">Write a brief explanation here</p>
    </div>
    <div class="col-12 col-lg-6 order-lg-2">
      <div class="border border-lg border-danger p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium">This is an example sentence.</div>
    </div>
    <div class="col-12 col-lg-6 order-lg-4">
      <div class="text-xlarge text-danger mt-2"><i class="icon icon-md line-height-1">close</i> Incorrect</div>
      <p class="mb-3 mb-lg-0 text-large">Write a brief explanation here</p>
    </div>
  </div>
</div>

Check out this pen to see the current setup: https://codepen.io/Daggett/pen/OKJxPm

The columns are responsive and should stack on smaller screens (hence the order-lg classes).

Answer №1

Make sure to include d-flex in the column to enforce the default stretch behavior and maintain consistent height. Additionally, add w-100 to the element to preserve its full width:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" >
<div class="container-fluid">
  <div class="row">
    <div class="col-12 col-lg-6 order-lg-1 d-flex">
      <div class="border border-lg border-success p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium w-100">This is an example sentence. It may go on for a couple of lines just to see what's going to happen!</div>
    </div>
    <div class="col-12 col-lg-6 order-lg-3">
      <div class="text-xlarge text-success mt-2"><i class="icon icon-md line-height-1">check</i> Correct</div>
      <p class="mb-3 mb-lg-0 text-large">Write a short explanation here</p>
    </div>
    <div class="col-12 col-lg-6 order-lg-2 d-flex">
      <div class="border border-lg border-danger p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium w-100">This is an example sentence.</div>
    </div>
    <div class="col-12 col-lg-6 order-lg-4">
      <div class="text-xlarge text-danger mt-2"><i class="icon icon-md line-height-1">close</i> Incorrect</div>
      <p class="mb-3 mb-lg-0 text-large">Write a short explanation here</p>
    </div>
  </div>
</div>

Answer №2

Utilizing the flex design of Bootstrap 4 rows and col-elements automatically ensures equal height. Simply setting the height of the inner div to 100% will make it fill its parent space. The Bootstrap 4 h-100 class can be used for height:100%;.

<div class="container-fluid">
  <div class="row">
    <div class="col-12 col-lg-6 order-lg-1">
      <div class="border border-lg border-success p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium">This is just a sample sentence. <br> It might span multiple lines to test the layout.</div>
    </div>
<div class="col-12 col-lg-6 order-lg-3">
  <div class="text-xlarge text-success mt-2"><i class="icon icon-md line-height-1">check</i> Correct</div>
    <p class="mb-3 mb-lg-0 text-large">Provide a brief explanation here</p>
</div>
<div class="col-12 col-lg-6 order-lg-2">
  <div class="h-100 border border-lg border-danger p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium">This is just a sample sentence.</div>
</div>
<div class="col-12 col-lg-6 order-lg-4">
  <div class="text-xlarge text-danger mt-2"><i class="icon icon-md line-height-1">close</i> Incorrect</div>
    <p class="mb-3 mb-lg-0 text-large">Provide a brief explanation here</p>
  </div>
</div>

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

I am experiencing an issue with the interaction between my "label" tag and "summary" tag. The details are not opening when I click on the label. Can someone please provide guidance on how to resolve this

I have reviewed the question here, but it does not provide an answer, and there's also this related question. However, my question has a slightly different angle. I am encountering an issue where adding another element inside the summary tag prevents ...

The Surprising Nature of <div> when containing <a> (anchor tags)

There are 3 div elements on a page. div { display: inline-block; margin: 10px; width: 200px; height: 200px; background-color: #333; color: white; text-align: center; } <div></div> <!--Div ...

Enhance your design with dynamic hover effects

I need assistance with modifying the menu structure generated by Wordpress. Specifically, I want to change the background of #header-nav li ul.children li a when #header-nav li ul.children li ul.children li a:hover is active. Could someone provide guidanc ...

Implementing a JQuery script that triggers every time there is a change in the scroll

This script creates a shrinking effect on a box followed by a fade-in/out transition when the scroll position changes. However, the issue is that it triggers every time there is a scroll position change. For example, if the scroll position is at 100px and ...

Angular's parent div height can be adjusted using CSS transitions

I have implemented a CSS transition to create a sliding effect in my pagination. However, I am facing an issue where the height of the containing div changes even when I set the position of the transitioned elements. Here is a snippet of my CSS: .slide { ...

Switch input-lg to input-sm in Bootstrap3 for smaller screens

One of my challenges is incorporating Twitter Bootstrap’s input-lg class on all input fields. I am wondering if there is a way, possibly utilizing JavaScript, to seamlessly switch to Twitter Bootstrap's input-sm class on smaller screens. This would ...

Issue with Flat-UI: Navigation bar is not collapsing correctly. Need help to resolve this problem

I am currently utilizing the most recent Twitter Bootstrap along with Flat UI. I have been trying to create a basic navbar that collapses when the screen size is reduced. How can I resolve this issue? This is how it currently appears: My navigation items ...

After installation, the Tailwind classes seem to be malfunctioning

Let me start by mentioning that although the title of this question is reminiscent of this other question on Stack Overflow, I have already tried the solutions provided there with no success. I initially attempted to set up Tailwind using their official C ...

CSS vertical alignment: Getting it just right

I am currently using Bootstrap and below is a snippet of the code I have implemented. <div class="row"> <div class="col-lg-6"><img src="#" alt=""></div> <div class="col-lg-6"> <h2>Heading</h2> ...

What is the best way to vertically center an amp-img element?

I'm attempting to vertically center an <amp-img> within a div. <div class="outer" style="height: 100vh"> <amp-img class="inner" layout="responsive"></amp-img> </div> I have tried various methods so far, but none seem ...

I am experiencing an issue where the custom form validation directive in AngularJS is not functioning properly within my modal

To enhance the validation of my input boxes, I created a custom directive called nx-validate. This directive is designed to be added to a bootstrap div.form-group, which will then check if the <input/> field is $dirty or $invalid, and apply the appro ...

Improving the efficiency of rendering multiple objects on a canvas

I'm currently working on developing a simulation for ants using the basic Javascript canvas renderer. Here is a snippet of the rendering code: render(simulation) { let ctx = this.ctx; // Clearing previous frame ctx.clearRect(0, ...

Looking for a Plugin that Can Responsively Display Images in a Vertical Layout - Does One Exist using Jquery

Looking for a gallery slider plugin that is responsive both horizontally and vertically. Have tried Flexslider1/2, Galleria, and others but they do not adjust to vertical resizing. Changing the CSS did not help. If you resize the browser horizontally with ...

When mousing over a subitem of the Image menu, ensure that the Image menu

Is there a way to prevent the image menu from reverting back to its original image when hovering over its subitems? I have 5 navigation menu items, but only one has a dropdown. Whenever I hover on the subitems of About Us, the image for About Us changes ba ...

I am having trouble with Node.js not properly handling POST requests and instead throwing a 505 error

I am a newcomer to nodejs and facing a roadblock in completing my project. I have been stuck for almost 2 days trying to resolve an issue with POST requests not being listened to by nodejs. Despite console logging, I keep getting a 405 error page. Here&ap ...

The dropdown function in Bootstrap seems to be malfunctioning

I have implemented a basic dropdown menu using the code below: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" ...

Endless Google Locations Instances

My database entries are being displayed in a table using input fields. I want the Location field for each entry to be automatically completed using Google's API. HTML: <input name="edit_airplane[1][location]" type="text" class="airplane_location" ...

Another option for handling a series of conditional statements instead of a bulky

Can someone help me with a coding issue I'm facing? I have an application that contains a large number of buttons which I need to trigger using keyboard presses. Currently, I am using a switch statement for this purpose. However, as the number of butt ...

Positioning an element absolutely inside a Material-UI React dialog

Currently, I am working on a Dialog component that includes a button located in the bottom right corner. When this button is clicked, it triggers the display of another div containing a list of items. However, I have encountered an issue where the list is ...

Receiving the result as well as encountering undefined initially during AJAX request

I have a dropdown menu, and when a user selects an option, an AJAX call is made to retrieve and display data based on the selected value. If the dropdown value is 2, it triggers the AJAX request. However, I am encountering two issues: https://i.sstatic.n ...