The parent container expands as the child container grows in size

I currently have a calendar on the left and a side bar on the right:

The issue I am facing is that the cases are overflowing. Ideally, I want to display a scrollbar when the content exceeds the height of its parent container.

These elements are contained within Bootstrap accordions.

Below is the HTML code:

 <div id="cal-container">
        <div id="cal-side">
            <div class="accordion" id="accordion2">
                <div class="accordion-group">
                    <div class="accordion-heading">
                        <a class="accordion-toggle project-header" data-toggle="collapse" data-parent="#accordion2" href="#project-list">Projects
                        </a>
                    </div>
                    <div id="project-list" class="accordion-body collapse">
                        <div class="accordion-inner">
                            <div class="event-container project-container">
                            </div>

                        </div>
                    </div>
                </div>
                <div class="accordion-group">
                    <div class="accordion-heading">
                        <a class="accordion-toggle task-header" data-toggle="collapse" data-parent="#accordion2" href="#task-list">Tasks
                        </a>
                    </div>
                    <div id="task-list" class="accordion-body collapse">
                        <div class="accordion-inner">
                            <div class="event-container task-container">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="accordion-group">
                    <div class="accordion-heading">
                        <a class="accordion-toggle case-header" data-toggle="collapse" data-parent="#accordion2" href="#case-list">Cases
                        </a>
                    </div>
                    <div id="case-list" class="accordion-body collapse">
                        <div class="accordion-inner">
                            <div class="event-container case-container">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <div id="cal">
            <div id='calendar'>
            </div>
        </div>
    </div>

The events are placed inside the event-containers.

Here is the CSS styling used:

#cal-side
{
    float:right;
    height:100%;
    width:200px;
    margin:50px 5px 5px 5px;
}

#cal-container
{
    width:100%;
}

.accordion-inner
{
    padding:2px 2px !important;
}

.external-event { /* mimicking the appearance of a real event */
    margin: 2px;
    padding-left:4px;
    color: #ffffff;
    background-color:blue;
    font-size: .85em;
    cursor: pointer;    
    -webkit-border-radius: 3px;
    border-radius: 3px;
    height: 20px;
    overflow:hidden;
    }

.event-container
{
    margin:1px;
}
#cal{ 
}

Below is some of the generated HTML:

I have attempted various methods for controlling the overflow including using `overflow:auto`. The only solution that somewhat worked was setting a fixed pixel amount as the max-height for the event-container, which displayed a scrollbar for cases. However, this is not the ideal solution as it does not adjust dynamically. I require the max height to match the height of cal-side or a similar approach...

Any suggestions on how to tackle this issue would be greatly appreciated.

Thank you

Answer №1

Ensure your container has a specified max-height and include overflow: auto

See it in action:

http://jsfiddle.net/DRVMG/13/

UPDATE The code snippet below is solely addressing a comment mentioned by the OP; I am not recommending the use of jQuery for their original question:

If you want to match the calendar's height with the sidebar, you can execute this:

$("#sidebar-id").css({"max-height" : $("#calendar-id").height() });

Additionally, remember to set the overflow property of the sidebar div to auto

Answer №2

Changing the overflow property alone does not affect how an element expands to contain its children. You must also set a specific height along with the overflow value, such as using auto.

Did you consider setting a height of 100% on the .event-container class? It may provide the desired result, but it's important to experiment with different options since the outcome can be influenced by the structure of the surrounding elements in the DOM tree.

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

When using Italics, the conflict arises between the specified line-height and the actual height of the

Recently, I encountered an issue that has me a bit perplexed: I have a span element with line-height set to 18px and font-size at 16px. Everything works perfectly when the text inside is regular; the height of the span remains at 18 pixels. The problem a ...

When an icon is hovered over in Vue, a text box popup will be displayed

Working on a personal project that requires obtaining the status of all devices within a unit. The status, along with the device name, is returned in an array from the function deviceStatus(). If all devices are currently marked as ON, the home icon next t ...

Establishing the value of "document.cookie"

Encountering issues while trying to set a cookie using different methods: Method 1: document.cookie = name + "=" + value + "; expires=" + date.toUTCString() + "; path=/"; This method only sets the value up to "name=value" wh ...

Adjust the color of text using the <text-shadow> technique

The default 'text-shadow' for white text in a <div> is defined as follows: When the text color is changed to #627CA9 by clicking on it, I want the 'text-shadow' to be updated to match the new color. text-shadow: 0 0 1px #FFFFFF, ...

Struggling with jQuery UI Draggable 1.10.3 bug in Firefox: Cursor center not detected when scrolling window

Before version 1.10.3, possibly 1.9.x, I didn't encounter this issue. However, after updating to jQuery UI 1.10.3, Firefox seems to have trouble locating the center of the cursor on the draggable plugin when the window is scrolled down. This problem ...

Error: The function expressJwt is not recognized as a valid middleware

As I delve into learning about middlewares, I encountered an issue when trying to import express-jwt. The syntax I used was: const expressJwt = require('express-jwt') To address the problem, I uninstalled the current version of express-jwt and i ...

Can you outline the key distinctions between AngularJS and ReactJS?

Looking to create a website that will be converted into a mobile application, I realize that my expertise lies more in desktop and Android native development rather than web client side development. After some research, I have decided to utilize HTML5, CSS ...

Why is Property CSS of Undefined Giving Error?

var random; var squareArray = [$('#square1'),$('#square2'),$('#square3'),$('#square4')]; var randomOrder = []; var i = 0; var j = 0; function computerPlays() { random = Math.floor(Math.random() * 4); randomO ...

Execute an HTTP POST request to the Node server, sending an empty object

For my project, I am attempting to send an HTTP Post request to my Node server from an html form. Despite using Body Parser and setting it up correctly, I am facing an issue where the req.body on my server is returning as an empty object. Can anyone prov ...

Is there a way I can insert an additional image directly behind my existing image using a pseudo element before or after? I tried it but it doesn't seem to be working. Are there any alternative methods I could try

Currently, I am attempting to include an additional image behind my current image by using a pseudo-element before, but unfortunately, it seems to not be working as expected. Are there any alternative methods to successfully add an image behind the origina ...

The parameter did not successfully transfer to the internal function within Firebase Cloud Functions

I am currently working on a Firebase cloud function that looks like this: exports.foo = functions.database .ref("/candidates/{jobTrack}/{candidateId}") .onCreate((snap, context) => { const candidate = snap.val().candidate; const jobTrack = ...

Alert displayed on console during transition from MaterialUI lab

Whenever I try to run my MUI application, an error pops up in the console It seems you may have forgotten to include the ref parameter in your forwardRef render function. import { LoadingButton } from "@mui/lab"; const LoadData = ({loading,sig ...

Dealing with dynamic CORS settings in Apache and PHP

Dealing with CORS has been quite a challenge for me. My javascript is sending AJAX Put/Fetch requests to an Apache/PHP script. In this particular scenario, the javascript is being executed on CodePen while the Apache/PHP script is hosted on a local serve ...

Image displayed on Silverlight website

I'm trying to figure out how to add a custom icon to our Silverlight application's web page. I've got the text covered using the Title property for the Page, but the icon is giving me trouble. Take a look at the image below. The tab on the ...

The script ceases to function once the page is loaded from a JSON file

I'm facing an issue on my shopping website where the items and products are loaded from a JSON file. The problem is that once the page has loaded, the script fails to work properly. If the items take a little longer to load on the page, the script doe ...

A guide on extracting an embedded image from an XML file using XSL

I have an image embedded directly in an XML file (not just the path, but the actual image bits). <image>Image pixels encoded in 64<image> So my question is whether it's possible to create a transformation using XSL to convert the XML fil ...

Using React Axios to Send Only the State Value of a Prop to the Backend

After successfully passing my parent state to my child component as a prop named title, I encountered an issue while trying to make a put request using axios with the value of that prop. The problem arose when attempting to use this prop's value in th ...

When attempting to call a bundle file using browserify from React, an unexpected character '�' Syntax error is thrown: react_app_testing/src/HashBundle.js: Unexpected character '�' (1:0

Hey there, I'm currently struggling with an unexpected unicode character issue. Let me provide some context: I've created a simple class called HashFunction.js that hashes a string: var crypto = require('crypto') module.exports=class H ...

I am puzzled by the issue with my logic - the button only changes once and then the onclick function ceases to work

I am having an issue with a button that should switch between displaying temperatures in Fahrenheit and Celsius when clicked. It works for the first two clicks, but on the third click, it stops working even though I've set the class back to .temp. $( ...

Deleting validation messages from my MVC controls

I set up some validation in my Model by adding the following code: [Required] [StringLength(60, MinimumLength = 4)] [Display(Name = "Users code")] public string UserCode { get; set; } When c ...