Design a row with two columns of the same height - one containing an image, and the other a scrollable

Can anyone provide guidance on creating two responsive Bootstrap 4 columns with equal height, where one column contains an image and the other displays a scrollable list?

Check out this fiddle (please note that I want to ensure the list group does not exceed the height of the image as the viewport is resized): https://jsfiddle.net/lgants/gyk31vow/

I've been struggling with this for days, so any assistance would be highly appreciated!

HTML:

<div class="row row-eq-height">
  <div class="col">
    <img src="http://lorempixel.com/output/sports-q-c-800-600-2.jpg">
  </div>
  <div class="col">
    <div class="card">
      <ul class="list-group">
        <li class="list-group-item">Cras justo odio</li>
        <li class="list-group-item">Dapibus ac facilisis in</li>
        <li class="list-group-item">Morbi leo risus</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
      </ul>
    </div>
  </div>
</div>

CSS:

img {
  max-width:100%;
  max-height:100%;
  object-fit: contain;
}

.list-group {
  overflow-y: scroll;
}

Answer №1

If you find yourself in this situation, the solution is to use JavaScript to calculate the height of the image and then set the height of the list to match it. Additionally, with Bootstrap 4 utilizing flex display on rows, make sure to align the columns by adding the class "align-items-start" to the row element. I am specifically working with Bootstrap v4-beta.

var picHeight = $('.pic-height').height();
$('.list-group').css('height', picHeight);

$(window).resize(function() {
var picHeight = $('.pic-height').height();
$('.list-group').css('height', picHeight);
});
img {
  max-width:100%;
  max-height:100%;
  object-fit: contain;
}

.list-group {
  overflow-y: scroll;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>


<div class="row row-eq-height align-items-start">
  <div class="col pic-height">
    <img src="http://lorempixel.com/output/sports-q-c-800-600-2.jpg">
  </div>
  <div class="col">
    <div class="card">
      <ul class="list-group">
        <li class="list-group-item">Cras justo odio</li>
        <li class="list-group-item">Dapibus ac facilisis in</li>
        <li class="list-group-item">Morbi leo risus</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
        <li class="list-group-item">Porta ac consectetur ac</li>
      </ul>
    </div>
  </div>
</div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

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

Struggling to retrieve the dynamic select list information from HTML and pass it to PHP. Any suggestions or guidance would be greatly

<form method="POST" name="mailform" action="sendmail.php"> <fieldset> <?php require_once("mysql_connect.php"); $sql = mysql_query( " SELECT NAME FROM TABLE WHERE ID = ( SELECT ID FROM TABLE2 WHERE COLUMN = '$USERNAME') ORD ...

Adjust the dimensions of a Three.js generated 3D cube dynamically during execution

Is it possible to dynamically change the dimensions (width/height/length) of a 3D Cube created with Three.js? For example, I found a Fiddle on Stack Overflow that changes the color of a Cube at runtime: http://jsfiddle.net/mpXrv/1/ Similarly, can we modi ...

What is the best way to choose a radio button when the page loads and extract its value at

After successfully setting a radio button to be selected upon page load, I am now facing the challenge of displaying the value of that button without the need to click on it. My goal is to toggle the visibility of different div elements, with the initial ...

The output of jQuery('body').text() varies depending on the browser being used

Here is the setup of my HTML code: <html> <head> <title>Test</title> <script type="text/javascript" src="jQuery.js"></script> <script type="text/javascript"> function initialize() { var ...

What is the best method to create a grey-colored background using CSS?

I'm curious about how they created the background on the page found at The background is not just a plain color - could it be an image that scales to fit the whole page? Or is there some CSS trickery involved? I noticed in the CSS that the body elem ...

Loop through a CodeIgniter database result object using Ajax

Hey there, I could really use your expertise on this one. I'm working with Codeigniter and my model is returning a database result object (not an array) to the controller. I need to iterate through this object using Ajax. Any suggestions on the best w ...

How to transfer the selected value of a drop-down list from one Action to another Action in MVC using Ajax techniques

I am currently trying to pass the selected value of a dropdown list from one action, "RMA," where I have my dropdown list, to another action, "ProcessRequestRMA," where I want to send the value of the dropdown list and then save it into the database using ...

Creating diagonal background cutouts using CSS

Can you create a diagonal cut in a background color using CSS? Check out this example https://i.sstatic.net/vtpYf.jpg .item { color: #fff; font-size: 30px; background-color: #565453; padding: 10px 10px 10px 10px; width: 52%; text-align: ce ...

What steps can I take to fix the issues on Safari that are being caused by three js on my website?

For my friend's birthday, I decided to surprise him by creating a web page for his online radio station. Being new to JavaScript, it was a great learning opportunity for me. After much experimenting, I finally got the page to work smoothly on desktop ...

Utilizing HTML Elements for Conditional Statements

I had a question regarding HTML code and JavaScript functionality that I came across while honing my coding skills. My curiosity lies in understanding how an HTML element can act as a boolean condition within a JavaScript while loop. Take, for instance, ...

AJAX and JSON-powered PHP form validation

My PHP script encodes validation in JSON, but I'm unsure how to integrate it into my main JavaScript function. Regular expressions are used in the PHP script to validate form criteria and I need to pass this information to the JavaScript file to displ ...

Automatically expanding PrimeNG Turbotable rows

I am using a PrimeNg turbotable that has a row expansion feature enabled. I am looking for a way to automatically expand the rows by default when the table loads. Shown below is my code: HTML <p-table [columns]="cols" [value]="cars" dataKey="vin"> ...

Clearing the view state of a specific repeater control

There is a specific requirement that I must fulfill, which involves deleting the view state of a particular repeater using jQuery or JavaScript. For instance, suppose I have two repeaters: repeater 1 and repeater 2. Upon clicking a button, I would like to ...

Ways to regain control of the iframe window once a popup has been launched

I have a question regarding managing windows in Javascript. In my application, when I click on a link within an iframe, it opens a popup window where I enter my login credentials. After entering the credentials, I am able to close the popup window using a ...

Has the submit button become inactive once it has been inserted into a collapse?

I have recently implemented a collapse feature and inserted a form into it, but unfortunately, the submit buttons are not functioning properly. They are failing to send the data to the PHP file. <div class="container"> <div class= ...

Is there a way to send an array with data to a different component using react-redux within a Higher Order Component (H

It seems like I'm missing something because I can't seem to find any examples of how to pass an array with data from a Higher Order Component (HOC) to another component. Here is the code snippet: import React from 'react' import NoAc ...

CSS navigation menu with drop-down functionality

I am currently learning CSS and HTML as I work on the CCTCcart project. When running the code in the bottom menu section, I noticed that when clicking on any menu item such as Products, the white background color merges with blue. I need to find a solution ...

Creating Visuals on HTML5 Canvas using Decimal Coordinates

Using rounded coordinates while drawing on canvas is essential for optimal performance. Floating coordinates can lead to unintended gaps on the canvas, particularly when mapping Google tiles onto a canvas. For example, 256x256 tiles work best when the star ...

The pqselect plugin in jquery is malfunctioning without any visible errors

I'm really struggling to get this plugin to work. It's the jQuery pqselect plugin for creating multiple select boxes with checkboxes. Even though I've followed the usage instructions, it still doesn't seem to be functioning correctly. ...

Using jQuery to apply a CSS border to an image within a textarea

Working with TinyIMCE, I am looking to incorporate a border around all images within the textarea whenever a user submits the form. $("form").submit(function() { var content = $("#edit-message1-value").val(); // Afterwards, I want to manipulate the cont ...