I'm looking to create a parent div that adjusts its size dynamically and can contain two child divs, each with variable sizes that can scroll independently. How can I achieve this?

Consider this layout configuration:

<div id="PARENT_DIV">
    <div id="LEFT_CHILD_DIV">

    </div>
    <div id="RIGHT_CHILD_DIV">

    </div>
</div>

Key features for PARENT_DIV:

  • PARENT_DIV must have a higher z-index than all other GUI elements.

  • PARENT_DIV should dynamically expand in width and height based on the sizes of LEFT_CHILD_DIV and RIGHT_CHILD_DIV. There should be limits set using max-width and max-height properties. For vertical expansion, it should match the taller child div (up to max-height), with the other child floating to the top.

  • The positioning of PARENT_DIV on the screen should be customizable through various methods like setting top and left values, percentages, or transformations.

Guidelines for LEFT_CHILD_DIV and RIGHT_CHILD_DIV:

  • LEFT_CHILD_DIV and RIGHT_CHILD_DIV should expand horizontally and vertically based on their content, following max-width and max-height restrictions set independently for each.

  • They should always appear side by side, regardless of their maximum widths.

  • If they reach the maximum height limit imposed either by max-height rules or the parent's max-height, vertical scrolling should activate to accommodate the overflowing content.

Refer to this visual mock-up for clarity on the desired layout. Despite trying various CSS combinations involving display, overflow, box-sizing, position, etc., I haven't found a single tutorial covering all requirements. Seeking insights on achieving these goals purely through CSS without resorting to JavaScript solutions.

While I can achieve this with JavaScript, preference is to explore a script-free CSS approach.

Answer №1

To implement a flexbox layout, follow these steps:

#PARENT_CONTAINER {
  position:absolute;
  top:50px;
  left:150px;
  border: 1px solid red;
  display: inline-flex;
  max-height: 200px;
  max-width: 300px;
  align-items: flex-start;
}

#LEFT_CHILD_DIV {
  border: 1px solid green;
  max-width: 180px;
  max-height: 100px;
  overflow: auto;
}

#LEFT_CHILD_DIV>div {
  height: 200px;
  width:200px;
  background:rgba(0,0,0,0.5);
  animation:change 2s infinite alternate linear;
}

#RIGHT_CHILD_DIV {
  border: 1px solid orange;
  max-width: 80px;
  max-height: 50px;
  overflow: auto;
}

#RIGHT_CHILD_DIV>div {
  width: 200px;
  height:300px;
  background:rgba(0,0,0,0.5);
  animation:change 2s 1s infinite alternate linear;
}

@keyframes change{
  to{width:5px;height:20px;}
}
<div id="PARENT_CONTAINER">
  <div id="LEFT_CHILD_DIV">
    <div></div>
  </div>
  <div id="RIGHT_CHILD_DIV">
    <div></div>
  </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

Button placed within a jade table cell

I'm struggling to make a button appear in each row of the table. I am new to working with Jade and Node.js, so I can't seem to figure out why it's not showing up. Here is my Jade file: html head body table.table.table(border='1 ...

During the click event, two distinct $.ajax requests interfere and cancel each other out

Here's a dilemma I'm facing: On my webpage, I have implemented two different click events. The first one opens a modal displaying a larger image when you click on a thumbnail picture (similar to Instagram on PC - I created an Instagram clone for ...

"Utilize Ajax to load PHP content and dynamically refresh a specific div

I have implemented an image uploading system, but now I want to incorporate a feature that allows users to rotate the uploaded images using Ajax. The challenge I'm facing is that if the session variable is lost during a full page update, I need to ens ...

Steps for properly inserting a hyperlink:

I'm in need of assistance. I have a grid containing several images that I want to make clickable by adding anchor tags, but when I do this, the images seem to disappear completely. I suspect there's an issue with them being inside the container d ...

Steps for displaying an HTML table in Excel by clicking on a button

My goal is to open an HTML table in XLS format with a single click of a button. Currently, I have a JavaScript function that allows me to export the HTML table to XLS using the "save as" option. However, I want to enhance this functionality so that clickin ...

Obtain data attributes using JQuery's click event handler

I'm facing an issue with a div structure setup as follows: <div class='bar'> <div class='contents'> <div class='element' data-big='join'>JOIN ME</div> <div class=& ...

Retrieve webpage using HTML stored in web storage

I am exploring a new idea for an application that utilizes local storage, and I am seeking guidance on the most effective way to load content after it has been stored. The basic concept of the app involves pre-fetching content, storing it locally, and the ...

Vanishing Span in CSS3 Flexboxes

I came across this particular HTML code: <div class="panel panel-info"> <div class="panel-heading">Person</div> <div class="panel-body"> <div class="data"> <p class="keys"> ...

My efforts to resolve the issues in my code have been ongoing, but unfortunately, I have been unable to find a solution

I'm struggling to insert my contact form code into the contact tab without it interfering with the tab bar. I want the form to appear in the middle of the page when the tab is clicked. I've tried various placements for the code but none seem to ...

Incorporate CSS and JavaScript files into every page of NetSuite

Is there a way to globally apply a CSS file or JavaScript code to all NetSuite pages in order to change the page direction to RTL? I attempted adding it through: SuiteScript >> Client >> Deployment : All Records, While I was able to successfully add them ...

Is it possible to modify a scss style in Prestashop?

I have encountered an issue while using a default theme in Prestashop 1.6 that I need assistance with. My goal is to move the navbar up by 25px. I understand that I should make changes to #block_top_menu { padding-top: 25px; } in blocktopmenu.scss, which ...

Employing AJAX to send form data to a pair of destinations

Can anyone help me out? I am having trouble using AJAX to submit my form to one location and then to another. Once it's posted to the second location, I want it to send an email with PHP to a specified recipient, but for some reason, it's not wor ...

Forming a header area by utilizing a 960 Grid container

I'm in the process of designing a website utilizing the 960 Grid system. The header consists of three parts: the logo, the navigation, and the login form. I've implemented media queries to center both the logo and the login section when the pag ...

Having trouble with jQuery Animate when trying to change the background-color property?

So, I was experimenting with the jQuery .animate() function and decided to change the background color of a div based on how many pixels the user scrolled. Surprisingly, it didn't work as expected. After switching to the .css() function instead, every ...

Utilizing the onCLICK event handler with numerous parameters

I'm in need of assistance with creating a function that involves multiple variables, preferably at least two... The table I am working with was generated using PHP and MySQL, all IDs were dynamically created which is why I am looking for a way to cap ...

Stop the span within the paragraph from breaking onto a new line

I have a situation where I need quote symbols to be placed inside span elements that are children of a p element. Each quote symbol requires slightly different CSS styles, and they must be included in the HTML rather than in the CSS due to backend restrict ...

Learn how to call class methods using jQuery events by utilizing the on() method

I'm attempting to create a reusable "component" using both HTML5 and accompanying JavaScript code that can be utilized multiple times. First, let's examine the HTML5 component code: <div class="listEditor" id="myStringList"> <div id="li ...

The content contained within the .each loop within the click event is only executed a single time

While working on coding a menu opening animation, I encountered an issue today. Upon clicking the menu button, the menu opens and the elements inside receive an added class (resulting in a fade-in effect). Clicking the menu button again should close the ...

The discrepancy between the heights of a div using Jquery and JavaScript

There is a container div encompassing all the site's content, which dynamically stretches. Additionally, there are multiple other divs that also stretch using the same method as in 20 other sites. Despite trying various methods with jQuery and JavaSc ...

The issue of checkboxes not being sorted properly in Slick Grid

Currently, I am working on resolving a sorting issue within one of our applications using Slick Grid for grid implementation. The existing sort function, although functional, presents a challenge. While it successfully sorts columns, the checkbox associate ...