Controlling Column Heights in Bootstrap 4 by Matching Heights with Another Column

Struggling with aligning the height of one column to match another? Let me break it down for you: I have a column (class: list) containing a list of discovered items - could be one, ten, or even twenty elements. The second column is where the description of the selected item goes, but its height isn't fixed due to various factors like resolution and external data.

I aim to make the left column's height equal to that of the second column. If the first column exceeds this height, I want to introduce a scrollbar to navigate through the additional items.

.list {
    background: #f77;
    overflow: auto;
}

.content {
    background: #ccc;
    height: fit-content;
    padding-bottom: 10px;
    padding-top: 10px;
    
}

li {
    height: 40px;
}
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8>;
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>bootstrap 4 column height</title>
  </head>
  <body>
    <div class="container py-2">
    <div class="row">
        <div class="col-md-4 list">
            <ul>
                <li>element 1</li>
                <li>element 2</li>
                <li>element 3</li>&
                <li>element 4</li>
                <li>element 5</li>
                <li>element 6</li>
                <li>element 7</li>
                <li>element 8</li>
                <li>element 9</li>
                <li>element 10</li>
                <li>element 11</li>
                <li>element 12</li>
            </ul>
        </div>
        <div class="col-md-6 content">
            <div style="height: 400px; background: #eee">
                variable height content
            </div>
        </div>
    </div>
</div>
  </body>
</html>

Answer №1

To create a flexible column layout, add the class d-flex,

<div class="col-md-4 d-flex">
  • Adding Flexbox height helps to equalize the elements.
  • Within the .box class, include width: 100% to adjust the width as needed.

You can see an example at https://codepen.io/yasinatesim/pen/NJgvYX

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

Manipulate the contents of children divs within a parent div using JavaScript or JQuery

<div id="abc"> <div id="a_b"> abcd </div> <div id="c_d"> xyz </div> </div> I have a challenge where the divs on my page are generated dynamically and their IDs change every time the page loads. When the window i ...

Tips for implementing varying styles depending on the number of columns in a table

I am working with multiple tables that share similarities, but differ in the number of columns each table has. I am looking to create a styling rule where depending on the number of columns, the width of each column will be set accordingly. For example, if ...

Maintaining the relative position of an SVG while scaling within a div element

I am in the process of incorporating my custom SVG knob icons into an electron application using flexbox. The challenge lies in keeping them centered within the rectangle icon regardless of browser size, as shown here. Ideally, the icons should adjust thei ...

Increasing the identifier of duplicated input fields using jQuery

There is a specific section in my form that consists of a select box and three checkboxes, which needs to be duplicated on request. While I have successfully cloned the div and incremented its specific div, I am facing challenges in incrementing the checkb ...

Find all elements with the same class and identify the first element among them using jQuery

In my dynamic data structure, I need to filter out all elements with the class name "My_data" and select the first one. In the code below, I am looking to retrieve the first element with the class "My_data". <div class="all_data"> <div class="lis ...

An issue occurred during the execution of the Django project

Hey there! I'm currently working on a Django project using Python, and I encountered an error while trying to run the project. Unfortunately, I'm not sure what the error is or how to resolve it. C:\Users\SujanRajs\Desktop\YAA ...

Trouble with jQuery delay in updating the CSS attribute while using fadeIn

After writing a simple JQuery code, I noticed that every time I click on 'eat', the animation lags. Is there any way to preload this animation for smoother performance? The #custom_menu element is a full-page section with a fixed position (simil ...

The sidebar should remain fixed on top when viewed on mobile devices, but not when viewed on desktop

Prior to beginning a new project, I'm interested in exploring the possibility of implementing a sliding sidebar for mobile and tablets. On desktop, however, I envision a fixed sidebar that is part of the main container layout as shown below: <div ...

Steps to alter background image and adjust its height upon function activation

I am working on a search page with an advanced search option that only certain users can access. I need the height of my div to increase accordingly and also change the background image to a larger size when the advanced search is selected. How can I make ...

Trouble with Angular 7: mat-tab active style not showing up

<div class="navigation"> > <mat-tab-group disableRipple="true" selectedIndex="0"> > <mat-tab label="Label1"> </mat-tab> > <mat-tab label="label 2"> </mat-tab> > & ...

hide the side menu automatically - wordpress

is the official website created using a WordPress platform. Upon visiting the site, you will immediately notice a prominent "showcase" banner positioned right below the navigation bar. On the right side, there are additional posts that users can choose t ...

Creating a cookie on click event to change the background

I am working on changing the background of a div onclick and storing it with a cookie. However, I am facing some issues with my code. I can't determine if the cookie has been properly set, and I am unsure about changing the background with the value o ...

Adjusting the selected state of an HTML/CSS checkbox with JavaScript

After downloading a theme with a tailored switch component that replaces the standard checkbox functionality, I noticed that the 'checked' status of the underlying checkbox does not change upon click or touch events. Here is the HTML structure: ...

Determine the differences in the content of the body section of an HTML file using

I am in the process of creating a shell script that can track changes on a website and send me an email with the content of the change if any. To achieve this, I am using wget to download a copy of the HTML and then comparing it to the version saved from t ...

Creating triangular shapes that can be interacted with by hovering

I'm trying to create a diagonal triangle on the screen that changes color when hovered over. However, my current method only creates a 'hack triangle' which is actually just a rectangle and doesn't respond to the transparent section. I ...

The functionality of a div element appears to be impaired when attempting to include a newline character

I have a div element <div id="testResult" style="padding-left: 120px;"> My goal is to include text with newline character '\n' inside the div. However, when I view my html page, the text does not respect the newline character. $( ...

Potential Issue with CSS General Sibling Selector

It seems like I have encountered a potential bug with the General Sibling Selector. When I use p ~ div, the selector does not work as expected. However, when I replace p with the specific class name text_paragraph, it works fine. You can view my code and f ...

How to center a responsive image in a container using Bootstrap

How can I properly center my banner and place the logo above it? Currently, both elements are not centered as desired. View the live version here: http://codepen.io/anon/pen/waYBxB HTML Code: </head> <body> <!-- LOG ...

Managing numerous range sliders in a Django form

My Request: I am looking to have multiple Range sliders (the number will change based on user selections) on a single page. When the sliders are moved, I want the value to be updated and displayed in a span element, as well as updating the model. The Issu ...

What are some ways to stop Visual Studio from splitting <% %> onto separate lines?

I have encountered a similar issue to this question, where I am struggling to make the formatting apply to ASP.NET server side tags <% %>. Just like the linked question, here is an example block: Good <ul id="menu"> <li><%: Html ...