Guide on how to make the parent scrollable once children are dynamically added

Do you know why the .wrap-max-height is not working properly?

I am expecting it to be limited by 100vh - 108px and for .ins to be scrollable if needed.

Any assistance would be greatly appreciated!

$('button').on('click', function(){
  let a = "<div class='abc'>ABC</div>";
  $(a).appendTo($('#ins'));
});
.wrap{
  position:fixed;
  left:50%;
  top:54px;
  transform:translateX(-50%);
  max-height:calc(100vh - 108px);
  background:silver;
  overflow:hidden;
}
.title{background:gold;}
.bottom{margin-top:5px;}
.sub{background:orange;}
.ins{overflow-y:scroll;}
.abc{background:lightgreen;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>CLICK</button>
<div class='wrap'>
<div class='title'>LOREM</div>
<div class='bottom'>
<div class='sub'>IPSUM</div>
<div class='ins' id='ins'>
<div class='abc'>ABC</div>
</div>
</div>
</div>

Answer №1

Adjust .ins with the following code:

    $('button').on('click', function(){
    let a = "<div class='abc'>ABC</div>";
    $(a).appendTo($('#ins'));
  });
.wrap{
  position:fixed;
  left:50%;
  top:54px;
  transform:translateX(-50%);
  max-height:calc(100vh - 108px);
  background:silver;
  overflow:hidden;
}
.ins {
overflow-y: auto;
max-height: calc(100vh - 108px);
}
.title{background:gold;}
.bottom{margin-top:5px;}
.sub{background:orange;}
.abc{background:lightgreen;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <button>CLICK</button>
    <div class='wrap'>
    <div class='title'>LOREM</div>
    <div class='bottom'>
    <div class='sub'>IPSUM</div>
    <div class='ins' id='ins'>
    <div class='abc'>ABC</div>
    </div>
    </div>
    </div>

Answer №2

To adjust the .wrap attributes, simply follow these steps and include min-width

.wrap{
  position:absolute;
    left:50%;
    top:60px;
    transform:translateX(-50%);
    max-height:calc(100vh - 120px);
  background:lightgray
  overflow:auto;
  min-height: 350px /* or any desired height for container stability with minimal content */
}

Answer №3

Effectively functions once the missing ";" is included here:

background:silver;

Additionally, the scroll requires a height.. thus, include a height for it to properly function.

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

Using conditional CSS in React/Next.js

While using Next.js, I have implemented conditional rendering on components successfully. However, I am facing an issue where the CSS styles differ between different components. Code 1: import React from "react"; import Profile from "../../ ...

Creating a Fixed Position Layout with Three Columns

Currently in the process of creating a 3-column website template and have been rearranging the divs to improve SEO. The issue I am facing is that the layout looks terrible when it's not fully loaded. Here is how it appears when it's not fully lo ...

An issue arises when attempting to utilize URL parameters within a loader

In my React project, I am utilizing React-Router. The code for my movie page is as follows: import React from "react"; import axios from 'axios' export async function loader({ params }) { const movieId = params.movieId; const mov ...

How do I switch the background-image on li hover and revert it back when I move off the li element?

Looking to update the background image of a div upon hovering over a li element? Check out this example here. So far, I've got that part working fine. But now I want the background picture to revert back to its original CSS when I move away from the l ...

Is it possible to find a different approach instead of relying on if or case statements in jQuery?

I have a collection of 10 pictures, and when each picture is hovered over, an ajax load event is triggered. I initially considered creating separate jquery hover functions for each image, but I feel there must be a more efficient solution. One idea I had ...

The system encountered a TypeError: Unable to access the 'nativeElement' property as it is undefined

Hello, I am a beginner in Angular 2 and currently working on an image cropping plugin. My goal is to display the image on a canvas element. Below is my HTML code: <div class="row"> <div class="col-sm-6"> <canvas id="layout" width="40 ...

Enhancing Functionality: JavaScript customization of jQuery (or any other object's) function

Within this jsfiddle, the author has created a test for a custom knockout binding. A key aspect of the test involves extending jQuery. My question pertains to lines 30. $.fn.on = function(event, callback) { where it appears that any existing definition o ...

jQuery does not permanently alter the values

It is unclear whether this issue is related to caching or coding. Interestingly, there seems to be inconsistency when attempting to modify the value of a div using text(); it works at times and fails at other times... EDIT SOLVED SEE BELOW: The problem wa ...

I am encountering a persistent 403 error in Django even after implementing csrftoken in my Ajax POST request. Can anyone shed light on

When attempting an Ajax POST request to retrieve news articles, I have encountered a persistent 403 error despite including a csrftoken in the headers. After searching online and attempting various solutions without success, I am left wondering: why does ...

Spread out the CSS grid dimensions to the descendants for the vuetify v-card image

I'm facing an issue with arranging vuetify cards with images in a CSS grid. The problem is that the grid size is not being recognized by the v-card's v-img because it's a grandchild element. How can I pass down the grid size to the v-img? M ...

What is the method to utilize the process.env object from within an imported npm package in the importing class?

In my React app, I used dotenv to set process.env variables for each component. When all components were in the same source code repo and imported via '../component/component_name', accessing these variables was easy using process.env.variable_na ...

What is the best way to extract the text from the first visible `<td></td>` table row using jQuery?

In this particular scenario, there is a table included: <table id="table"> <thead> <tr> <th>Name</th> <th>Course</th> </tr> </thead> <tbody> <tr style="display:none"> ...

When resizing an anchor tag with a percentage in CSS, the child image width may not scale accordingly

In short, I have multiple draggable images on a map enclosed in anchor tags (<a><img></a>) to enable keyboard dragging. The original image sizes vary, but they are all too large, so I reduced them to 20% of their original sizes using the ...

I am having trouble getting Form.Select to work in my basic react-bootstrap application, despite following the guidelines provided in the react-bootstrap documentation. Can

I am new to utilizing "react-bootstrap with hooks" and currently in the process of creating a basic form. I have been following the guidance provided by react-bootstrap documentation, but I encountered an issue specifically with select/option form elements ...

JavaScript enables running Acrobat Run profiles with variables

Is it possible to set a value to a preflight created using Acrobat before running it? var oProfile = Preflight.getProfileByName("myPreflight"); var oThermometer = app.thermometer; var textSize = 10; //oProfile.SetVariable("textSize",t ...

Is all of the CSS stored in one or multiple files?

Will the number of CSS files on my website impact its performance? I understand the necessity of having a separate file for print styles, but I'm wondering about the other CSS files. Is it better to have all my styles in one file or split them into mu ...

CSS: Issue with rounding errors in Em units

Recently, I decided to update the CSS file for a website I'm working on by making most elements and fonts dynamic in size using the em unit instead of px. The new sizes seem to be working, but there's an issue that's been bothering me. It s ...

When using v-select to search for items, the selected items mysteriously vanish from

I recently worked on a project where I encountered a similar situation to the one showcased in this CodePen. Here is the link to the specific CodePen One issue I faced was that the selected items would disappear when performing an invalid search. After i ...

Fade out the content using jQuery and simultaneously change the div

I stumbled upon this interesting code snippet here: http://jsfiddle.net/7hqyq/ Being a novice in the realm of jQuery, I am curious to learn how one can modify the background color of the selected square (including the first square on page load) and implem ...

Interested in transferring an additional column value to the $scope.seriesSelected variable?

I've been delving into Timeline charts using the angularjs google chart API and have come across an interesting limitation. It seems that only 4 columns are allowed, with the extra column designated for tooltips. However, I have a specific requirement ...