Determine the height of the left div, which is set to auto, and apply the same height to the right div, which has overflow set

I am facing an issue that needs a solution. I need to ensure that two div elements have the same height. The left div should have 'auto' height while the right one must match it. Moreover, the right div contains 14 nested divs that need to be scrollable.

Below is the code snippet:

#episodenbox {
    margin-top: 62px;
    width: 960px;
    margin-left: auto;
    margin-right: auto;
    height: auto;
}

#titelbox {
    width: 960px;
    height: 50px;
    background-color: #ffffff;
}
...
<div id="left">
    <div id="titelbox">
        <p>Episode 01: Encounter</p>
    </div>
    <div id="thumbnail">
        <img id="episodenimg" src="Episode%2001.png">
        <p>A mutant shaped as a young girl breaks out of an underground research lab, killing 23 security guards in the process. Teenagers Yuka and Kohta encounter the mutant on the beach, who seems to have lost its memory due to a gunshot wound.</p>
    </div>
</div>
<div id="right">
    <div id="untertitelbox">
        <p>Other Episodes:</p>
    </div>
        <div id="episodenbox1">
            <a href="Episode%2002.html"><div id="episode2">
                <img src="Episode%2002.png">
                <p>Episode 02: Annihilation</p>
            </div></a>
            ...
        </div>
    </div>

Answer №1

I attempted to replicate a similar situation in this code snippet

Kindly verify if this solution resolves the issue. My approach assumes that once the page loads, the height of the left div remains constant. If it changes dynamically, additional JavaScript will be required to monitor and adjust the height of the right div.

Answer №2

If you're looking for a solution, consider using CSS Tables with the display: table property.

Below are the key points summarized from the provided code to enhance readability.

.table {
  display: table;
  border-collapse: separate;
}
.row {
  display: table-row;
}
.col {
  display: table-cell;
  padding: 30px;
}
.content {
  background: #EEE;
  width: 960px;
}
.list {
  background: #BBB;
  width: 316px;
}
<div class="table">
  <div class="row">
    <div class="col content">
      <h1>Episode 01</h1>
      <!-- Your Video goes here -->
      <p><strong>This column has an automatic height. The other column's height will have the same height as this column</strong></p>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>
    <div class="col list">
      <h2>Andere Episoden:</h2>
      <ul>
        <li><a href="#">Episode 1</a></li>
        <li><a href="#">Episode 2</a></li>
        <li><a href="#">Episode 3</a></li>
      </ul>
    </div>
  </div>
</div>

Answer №3

To solve this issue, you can place a wrapper with relative positioning around both columns and fix the position of the right column.

/* solution */
#wrapper {
  overflow: hidden;
  position: relative;
  max-width: 1040px; 
}

#right {
  overflow-y: scroll;
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 380px;
}

#episodenbox1 {
  width: 340px;
  overflow: hidden;
}

#episodenbox {
  margin-top: 62px;
  width: 960px;
  margin-left: auto;
  margin-right: auto;
  height: auto;
}
#titelbox {
  width: 960px;
  height: 50px;
  background-color: #ffffff;
}
#titelbox p {
  margin-left: 6px;
  color: #000000;
  font-size: 30px;
  text-align: left;
  text-decoration: none;
  line-height: 50px;
}
#thumbnail {
  background-color: #ffffff;
  float: left;
  margin-top: 12px;
  width: 632px;
  height: auto;
}
#thumbnail p {
  width: 616px;
  color: #000000;
  font-size: 19px;
  margin: 0px 6px 6px 6px;
  text-align: left;
  text-decoration: none;
}
#episodenimg {
  width: 620px;
  height: 349px;
  display: block;
  margin: 6px 6px 6px 6px;
}
#untertitelbox {
  margin-left: 12px;
  margin-top: 12px;
  background-color: #ffffff;
  float: left;
  width: 316px;
  height: 40px;

... (truncated for brevity)

      </a>
    </div>
  </div>
</div>

In order to make this solution responsive, you will need to add @media queries to ensure that the absolute positioning is only applied when necessary and does not disrupt the layout on smaller screens.

Answer №4

One can achieve the desired layout without relying on JavaScript or fixed-height tables by using flex-boxes.

To implement this method, the key is to enclose the <div>s in a containing div, referred to as #scroll. By positioning it relatively within its parent and absolutely within itself, the container will expand to fit the remaining space without stretching the wrapper/container. Setting top: 0; bottom: 0; for

#scroll</code allows for creating the desired scrollable area for the content.</p>

<p><div>
<div>
<pre class="snippet-code-css lang-css"><code>#episodenbox {
    margin-top: 62px;
    width: 960px;
    margin-left: auto;
    margin-right: auto;
    height: auto;
}
 /* Rest of the CSS code removed for brevity */
#wrapper{
display: flex;
}
#right{
display: flex;
flex-direction: column;
}
#untertitelbox{
flex: 0 0 auto;
}
#episodenbox1{
flex: 1;
position: relative;
}
#scroll{
position: absolute;
top: 0;
bottom: 0;
overflow: auto;
}
<div id='wrapper'>
  <div id="left">
      <!-- Content here -->
  </div>
  <div id="right">
        <!-- Modified content with added scroll container -->
    </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

"Utilizing JSON parsing in Node.js and rendering the data in a Jade template

I need assistance with parsing JSON and presenting the response in a tabular format using Jade. Can you help me display the key-value pairs in two separate columns? Node.js exports.postMQinput = function(req, res) { req.assert('name', 'Q ...

find the next earliest date in the array after the specified date

How can I find the smallest date in an array of dates that comes after a specific date? var datesArray = ['2019, 10, 4', '2019, 10, 13', '2019, 10, 8', '2019, 10, 6']; ownDate = '2019, 10, 05'; I need to ...

Utilize Express efficiently by requiring modules only once for multiple routes within the application

Here is an overview of my project directory structure: MyProject -app.js -routes -routeone -routetwo In the app.js file, I have the following setup: var express = require('express'); var app = express(); var routeone = ...

CSS guidelines for layering shapes and divs

Currently, I am in the process of developing a screenshot application to enhance my understanding of HTML, CSS, and Electron. One of the key features I have implemented is a toggleable overlay consisting of a 0.25 opacity transparent box that covers the en ...

Switching an image when hovering over another div - a simple tutorial

Currently, I am in the process of creating a product page for metal address numbers on a website. These numbers are available in four distinct colors: gold, chrome, black, and brown. My goal is to enable users to hover over a specific color div, prompting ...

Guide on verifying the presence of an alert with nodejs webdriver (wd)

I am currently facing a challenge when writing a test where I need to verify the existence of an alert, check its text if it is present, and then accept it. Although I have researched on platforms like Stack Overflow for solutions such as checking for ale ...

PHP Header Redirect Not Redirecting Correctly

As a newcomer to PHP, I conducted some research and attempted to implement a solution found on Stack Overflow, but unfortunately, it did not work for me. My goal is to redirect users to another page after a specific code has been executed. Despite removing ...

An issue arose when trying to implement react-router within a multi-step registration process

While working on my multi-step registration form, I encountered an error when implementing react router. Clicking on the personal info link led to the following console errors: "Uncaught TypeError: Cannot read property 'ownerName' of undefined" ...

Steps to achieve overflowing text above the border-top just like with the border-bottom when setting the height to 0px

Can text be vertically aligned above the border-top in HTML when using height:0px, similar to how it can be done below the border-bottom? HTML: <ul id="experiment" style="background: #FFDD00;"> <li id="test1"><span class="v-align-bot"& ...

When watching YouTube videos in full screen mode on F11, the IFrame zooms in excessively, causing the video quality to suffer

After using the same code as the website Virtual Vacation, I noticed that they are experiencing the same issue as me. I am considering reaching out to them to inform them about it, but I am struggling to find a solution on my own. Specifically on WINDOWS ...

Exploring the tab-content features of Bootsrap 5 through anchor tags

In the previous version of Bootstrap, the tab-pane used to fade in active. However, in the new version, it is now: tab-pane fade show active. What other improvements can I make? <!DOCTYPE html> <html lang="en"> <head> <m ...

Extract value from child div using JQuery and update text in another section of the page

Here is a fiddle showcasing the concept I am working on: https://jsfiddle.net/wvz9p3e7/1/ The code is written in PHP and involves a loop for cycling through 7 or 8 different garments. My goal is to have the window on the right side of the fiddle display t ...

Plunker fails to run simple AngularJS demo

I'm having trouble figuring out why this basic example isn't functioning as expected on Plunker. http://plnkr.co/edit/EfNxzzQhAb8xAcFZGKm3?p=preview var app = angular.module("App",[]); var Controller = function($scope){ $scope.message ="Hel ...

Problem of background and shadow blending in CSS

I'm experimenting with creating an element using a radial gradient effect. My initial approach was to use a white circular container and apply a white box shadow. However, I encountered some issues where the color of the shadow did not match the backg ...

"Flashes of canvas in constant motion between animated scenes

I have a practical exercise to do for school, but I am very new to HTML/JS. The issue I am facing is that my canvas is flashing, like it erases one image and then quickly displays another. I want both images to be displayed at the same time. Here is the co ...

Using Yii to attach an onclick event to CLinkPager for every pager link

Is there a way to execute a function with every pager link click in Yii's CLinkPager? I've tried the following code without success. 'pagerCssClass' => 'pagination', 'afterAjaxUpdate'=>"FB.Canvas.scrollTo ...

Responsive design for iPads and smartphones is essential in ensuring a seamless user

Currently in the process of creating my own personal website, I have been diligently using Chrome Canary to ensure that all my media queries are properly set up. While everything looks great on Canary and functions well in various device modes within the b ...

What is the method for invoking a JSON web service with jQuery that necessitates basic authentication?

My knowledge of javascript is limited, but I am attempting to access a JSON web service that requires basic authentication using jQuery. Unfortunately, my searches on Google have not yielded any useful results. Can anyone tell me if what I am trying to a ...

What is the best way to handle JSONp response parsing using JavaScript?

I'm relatively new to working with Javascript and I am currently attempting to retrieve data from an External API located on a different website. My goal is to extract the information, parse it, and then display specific parts of it within my HTML pag ...

Tips for implementing Peer.js in Next.js using TypeScript?

Next.js has the ability to run on the server side, which can result in Peer.js throwing errors when used with Next.js. One user on Stack Overflow explains this issue: The error is likely due to peer js performing side effects during import. The suggest ...