Setting the parent's height to match one of its children

I'm struggling to align the height of the pink '#images-wrap' with the main image. When there are too many small rollover images on the right, it causes the pink div to extend beyond the main image's height. If I could make them match in height, I could then use overflow hidden to hide the extra rollover images below and enable scrolling for viewing them.

Using a table layout doesn't solve the issue. Although using child div elements with hidden overflow seems like it should work, setting the height causes problems with image aspect ratios. The 3:2 aspect ratio of the images must be maintained.

The attempted javascript solutions fail to retrieve the image heights. Even fetching the child image height proved unsuccessful.

If anyone knows a magic trick to accomplish this, your advice would be greatly appreciated!

Answer №1

To implement a flexible layout, apply the display: flex property to the main container:

#content-wrap {
  width: 100%;
  height: auto;
  margin-top: 25px;
  float: left;
  display: flex;
}

#info-wrap {
  width: 100%;
  height: 325px;
  float: left;
  text-align: right;
  position: relative;
}

#main-content {
  width: 80.5%;
  float: left;
  background-size: cover !important;
  background-position: center center !important;
  height: auto;
}

#main-content>img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
}

#thumbnails {
  width: 17.5%;
  height: auto;
  float: left;
  margin-left: 2%;
  overflow-y: scroll !important;
}

.thumbnail {
  margin-bottom: 6px;
  background-position: center;
  background-size: cover;
  height: auto;
}

.thumbnail:last-of-type {
  margin-bottom: 0;
}

.thumbnail>img {
  height: auto;
  width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="content-wrap">
  <div id="main-content" style="background-image: url('http://example.com/image.jpg')">
    <img src="http://example.com/thumbnail.jpg" id="image-sizer">
  </div>
  <div id="thumbnails">
    <div class="thumbnail" onmouseover="$('#main-content').css('background-image', $(this).css('background-image'));" style="background-image: url('http://example.com/thumbnail1.jpg')">
      <img src="http://example.com/thumbnail.jpg">
    </div>
    <div class="thumbnail" onmouseover="$('#main-content').css('background-image', $(this).css('background-image'));" style="background-image: url('http://example.com/thumbnail2.jpg')">
      <img src="http://example.com/thumbnail.jpg">
    </div>
    <script>
      // adjust overflow if less than 5 thumbnails
      var thumbs = document.getElementsByClassName('thumbnail');
      var thumbsContainer = document.getElementById('thumbnails');
      if (thumbs.length < 5) {
        thumbsContainer.style.overflow = 'hidden';
      }
    </script>
    <script>
      // ensure '#thumbnails' height does not exceed '#main-content'
      var mainContentHeight = document.getElementById('image-sizer').style.height;
      var thumbnailContainerHeight = document.getElementById('thumbnails').style.height;
      if (thumbnailContainerHeight > mainContentHeight) {
        document.getElementById('thumbnails').style.height = mainContentHeight;
      }
    </script>
  </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

"Implement a feature to recognize and handle various file extensions within an npm

I need help with my npm script where I am trying to include both ts and tsx file extensions. My current code snippet is as follows: "test": "mocha ..... app/test/**/*.spec.{ts,tsx}" Unfortunately, the above syntax is not working correctly. Can someone pl ...

Challenges in Ensuring Proper Alignment of Connection Line Between Boxes on Left and Right Sides within a React Component

Currently, I am developing a React component that displays two sets of boxes on the left and right sides of the screen. Users can choose one box from each side and click a "Connect" button to draw a line between them. However, I am encountering an issue wh ...

Determine the size of v-flex in Vue / Vuetify

Vuetify provides the v-resize directive, which is demonstrated in an example using window size. I am interested in utilizing this directive to monitor the size of a specific component (e.g. v-flex). In the provided codesandbox example, the objective is t ...

Ways to enhance background removal in OpenCV using two images

I am currently using OpenCV in conjunction with NodeJS (opencv4nodejs), and I am working on a project that involves replacing the background of webcam images. I have one image with a person's head in the frame, and another without. My code is functio ...

Avoid navigating to the subscribe block when the server sends a response in Angular

When trying to send a request to the server and check the response, I am not seeing any results. The code for sending the request is below: SendVerificationInfo(item: SendVerificationModel): Observable < any > { return this.httpClient.post < any ...

Preventing the upload of empty images in an angular application

When selecting multiple images for upload, I sometimes need to make changes or delete the chosen images before actually uploading them. However, if any of the selected images have a size of 0B, I want to stop the upload process for all images, not just the ...

When attempting to call a recursive method in Vue with a changing `this` object, an error is thrown: "RangeError: Maximum call stack size exceeded"

Update integrate codePen into the project. https://codepen.io/jiaxi0331/pen/xxVZBMz Description encountered an issue while trying to call the parent method recursively Code export default { methods: { dispatch(componentName, event, value) { ...

Having Trouble with the Background Video Scaling on My HTML Bootstrap Page for Mobile Devices

I have been working on an HTML background video page, and everything seems to be working perfectly on desktop. However, when it comes to mobile, the video does not cover the full screen. Only half of the video is visible on the mobile screen. Here is the ...

Initially, the 'display none' CSS command may not take effect the first time it is used

I am currently working on a slideshow application using jquery.transit. My goal is to hide a photo after its display animation by setting the properties of display, transform, and translate to 'none' value. Although the slideshow application work ...

JavaScript and jQuery: The Power of Dynamic Arrays

Even though my var email contains a string data, why does my array length always turn out to be 0? (I've confirmed that the data is there by using alert on var email). var emails = new Array(); //retrieve all the emails $('.emailBox ...

Generate a visually dynamic representation of a live website page

I'm curious if it's possible to create a login page similar to the one shown in this image, using HTML, CSS, and Javascript. Instead of a traditional background image, I want the background to display the actual layout of another website, such a ...

Adjusting Iframe Dimensions Dynamically with Javascript based on Anchor Location

I am experienced with handling this issue in flash, but I am struggling to figure out how to do it using Javascript and CSS. The problem involves an iframe that does not have an overflow property, and I need to modify its width/height. Is there a simple ...

Utilize Meteor-tabular to effortlessly export data with convenient HTML5 export buttons

Currently, I am utilizing the tabular package to display data from a collection in a table format. However, when attempting to export the data using html5 export buttons with the button (csvhtml5), only the length of data visible in the table is exported, ...

The login form is not being recognized by Chrome

I've been working on creating a login form for my website. Oddly enough, when I try to use it on Chrome, it doesn't prompt me to save my password. Yet, it functions properly on other browsers like Edge, Firefox, and Internet Explorer. Here' ...

Encountering error ORA-12514 when utilizing the node oracle-db npm package

At the moment, I am immersed in a project that relies on utilizing oracle for its backend. Following the instructions provided in this link, I successfully installed node-oracledb on my Mac using npm. The contents of my file are as follows: var oracledb = ...

javascript Incorrectly using location.reload will not refresh the page as intended

My goal is to refresh a page every time a user clicks a button so the page reverts back to its original source code. However, I am facing an issue where the location.reload() function is being executed after the code instead of at the beginning. btn.addEve ...

Showcase your skills in CSS, HTML, and Javascript

I attempted to search for something similar but came up empty-handed. I have two buttons. When I click one of them, I want to hide a certain division, but it's not working as expected. The divs d2 and d3 are initially hidden when the page opens, whic ...

How can an Angular Component be created in the browser using the standard method?

Attempting to develop a basic Angular example using JS/ESM. It has been some time since working within the angular environment, and there appear to be two primary choices: Utilizing the UMD lib (preferably to be avoided) Using the ESM2015 folder and loadi ...

Divergent Appearance of Input Field in Chrome versus Firefox

After testing in Chrome and Firefox, I noticed that the input box appears larger than expected in Firefox. Below is the HTML markup: <div class="form-wrapper"> <input type="search" name="Ofsearch" placeholder="Search h ...

The HTML table inexplicably displays a random comma out of nowhere

When working on my HTML table, I noticed that it was rendering a comma unexpectedly. I am using Nodemailer and SMTP Google server, and I suspect the issue lies within the HTML code. However, I am struggling to identify the exact problem. https://i.stack.i ...