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

What is the reason behind both paragraphs being displayed in a shade of blue in this snippet of code

.red p { color: red; } .blue p { color: blue; } <div class="blue"> <p> first </p> <div class="red"> <p> second </p> </div> </div> Initially, I expected the first paragraph to be bl ...

What is the best way to prioritize List Items over menu items in the front?

Sorry if the title is unclear, let me clarify with some images. First, here is how the navigation bar looks in full window view: Now, this is what happens when I decrease the screen resolution: The items list seems to be hiding behind the menu items. Ho ...

Incorporate a genre twist in animated films

Is there a way to implement an animated feature where the letters appear one by one in between a sentence, similar to what is seen on this page? On the linked page, there is a sentence displayed inside a banner that reads: Create meaningful documents Cr ...

JavaScript may fail to execute properly if the <!doctype html> declaration is not inserted in the correct syntax

While building a web page, I encountered an issue with my JavaScript code not working when using <!doctype html> or any type of <!doctype> at the top of the page. Can someone explain this error? After researching online, I learned that <!do ...

Guide on creating a stationary side navigation bar in HTML with Bootstrap 5 and CSS

I am developing a website with a fixed side navigation bar that stays in place when scrolling through the content section. I experimented with both the fix-position in Bootstrap 5 and CSS methods, but no matter how I set it up, the side bar remains transpa ...

Profile picture placeholder with conditional logic

After extensively searching online, I was unable to find a solution on how to add a default profile picture. Here is the code snippet I used for uploading an image chosen by the user: <td><img class="image" src="image/<?php echo $contact[&apos ...

The v-bind class feature is failing to update the CSS on the object's properties

I'm attempting to dynamically modify the CSS of certain buttons based on object properties within a list. Below is the data I am rendering out, and despite following the documentation and ensuring my setup is correct, I seem to be overlooking somethin ...

Executing a nested function as an Onclick event in an HTML document

I am currently working on a project within the Phone Gap framework where I need to transfer values from one HTML page to another. My solution involved using the code snippet below. var searchString = window.location.search.substring(1),i, val, params = s ...

Implementing change event to activate select dropdown with jQuery

Is there a way to modify the code so that select2 and select3 are disabled by default, but become enabled only when an option is selected in the previous select dropdown (excluding the placeholder "Select your option")? In addition, I want the first place ...

Does ng-bind have the ability to function with input elements too?

My mind was spinning as I tried to figure out why my <input ng-bind="x.a * x.b" tabindex="-1" readonly/> expression wasn't functioning. The use of ng-model was not an option due to the fact that the product is not an L-value, so I made the swi ...

Tips for incorporating circumflex accent in an HTML textarea

I have a textarea in my HTML file where I need to use circumflex accents, allowing users to type characters like: ŝĝĉ However, when I try to type these characters, nothing happens. What could be causing this issue? I have already included: <meta ...

Switch up the placement of articles, going back and forth between left

On the page, I want to display articles with alternating positions - one on the left, the next on the right. In this example, all the articles are currently being displayed twice, both on the left and the right side. How can I ensure that only one instanc ...

Create unique identifiers for the TD elements of Viz.js that will be displayed within the SVG elements

Below is the DOT code snippet in Viz.js that I am working with: digraph G { node [fontname = "font-awesome"]; 17 [id=17, shape="hexagon", label=<<TABLE BORDER="0"> <TR><TD>undefined</TD></TR> <TR><TD>[47-56]< ...

Arranging Bootstrap 4 columns in a vertical stack

My HTML code is as follows: <html> <head> <title>Title</title> <meta charset="utf-8"> <meta name="description" content="description"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <li ...

Create a stylish navigation dropdown with MaterializeCSS

Incorporating the materializecss dropdown menu feature, I encountered an issue where only two out of four dropdown menu items were visible. Here is the HTML code snippet in question: <nav class="white blue-text"> <div class="navbar-wrapper con ...

Having trouble dividing an HTML file?

Currently, I am working on creating a very basic web page that is divided into two parts. Each part will have its own HTML file: Welcome.html & Welcome.css: <html> <head> <link rel="stylesheet" type="text/css" href="Welcom ...

Correcting the reference to "/" (root) for assets after relocating the site to a subdirectory

I currently have a website located in the public_html directory, where all assets (images, css, js, etc) are referenced using /asset_folder/asset. The "/" at the beginning ensures that the browser starts from the root and navigates through the directories. ...

sidebar that appears upon the initial page load

I'm currently working on implementing a sidebar navigation panel for my website using JavaScript, HTML, and CSS. However, I am facing an issue where the sidebar automatically opens when the page is first loaded, even before clicking on the icon to ope ...

Methods like jQuery blink(), strike(), and bold() offer dynamic ways to manipulate

I'm currently tackling an inquiry. The code I crafted seems to be functioning without any issues: (function () { if($('#target:contains("bold")')) { $('#target span:first').css('font-weight','bold ...

Tips for customizing the appearance of material-ui SelectField

Currently, I am utilizing material-ui alongside react with the version "material-ui": "^0.19.2". I am facing an issue while attempting to embed a SelectField inside a table. Although the functionality is working smoothly, there are two unexpected behaviors ...