Automatically Scrolling Div According to its Content

Struggling to figure out how to make a parent div automatically scroll based on its child's content.

I have a menu that expands when clicked and needs to scroll if the height of the child exceeds that of the parent.

This is the HTML for the menu wrapper.

<div class="menu-box">
            <div class="page-links">
                <div class="pl-inner">
                    <div class="pl-box">
                        <div class="pl-content">
                            <p>Menu content goes here......Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div> 

This is my CSS

.menu-box {
            width: 100%;
            min-height: 100%;

            

background-color: #000;

                position: fixed;
                z-index: 10;

                transition: all 1.5s ease-in;
            }

            .page-links {
                width: 100%;
                height: 100%;

                position: relative;
                top: 0px;
                left: 0px;

                overflow-y: auto;
                -webkit-overflow-scrolling: touch;

            }

            .pl-inner {
                position: relative;
                width: 100%;
            }

            .pl-box {
                position: relative;
                top: 0px;
                right: 0px;
                bottom: 0px;
                left: 0px;

                padding: 120px 50px 180px 50px;

                overflow:  hidden;
            }

            .pl-content {
                width: 100%;
                display: inline-block;
                opacity: 1;
                color: white;
            }

You can see a working example here.

I thought adding overflow-y: auto to the parent element would automatically scroll the content, but it doesn't seem to work even when I resize the screen vertically. Where am I going wrong?

Answer №1

This snippet is located at line 12 in the CSS file.

body {
    overflow-y: hidden !important; // Keeping this as auto will enable scrolling for your body
    overflow-x: hidden;
}

The issue arises from setting the overflow-y of the body to hidden, which prevents scrolling capability for the body element.

Answer №2

Is this what you're looking for? View it in full screen and tell me your thoughts.

$('.burger-wrapper').on('mousedown' , function(){
                $('.content-wrapper').toggleClass('show');
            });

Answer №3

After some experimentation, I discovered that the solution is to change the position of .page-links to absolute

I'm not sure if this is the best way to organize things, but it seems to be effective. You can view the updated Code Pen here

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

Methods for altering the color of a div using addEventListener

Why doesn't the color change when I click on the div with the class "round"? Also, how can I implement a color change onclick? var round = document.querySelector(".round"); round.addEventListener("click", function() { round.style.backgroundCol ...

jQuery Accordian malfunctioning for all elements except the first one in the list

Trying to implement an accordion feature that can be utilized across the entire website. The current logic seems to be partially functional... When I click on any of the accordions, it should open by adding a 'show' class, but this only works for ...

What causes the transformation from "&" to "&amp;" upon the completion of page loading?

While using Firefox and working on a page, I noticed that & turns into &amp;. Normally, I would fix this with html_entity_decode(), but it's not working in this case. Then I stumbled upon something interesting. An alert is triggered once the ...

Adjust the class of the iframe element when clicked

I am attempting to change the class of an iframe (soundcloud embedded track) when it is clicked, in order to apply different properties. However, my code doesn't seem to be working as expected. Here is what I have: Here is a snippet from my index.htm ...

In order to comply with JSX syntax rules in Gatsby.js, it is necessary to enclose adjacent elements

I want to apologize beforehand for the code quality. Every time I attempt to insert my HTML code into the Gatsby.js project on the index.js page, I encounter this error: ERROR in ./src/components/section3.js Module build failed (from ./node_modules/gatsb ...

Loading input datalist in Firefox postponed

My goal is to implement an input field for a username that allows users to select from a wide range of names/usernames. I want them to be able to enter a partial string from the name or username. Instead of loading the entire list initially, I aim to load ...

Is the mobile site displaying CSS pixels in the physical pixel resolution?

I am struggling to grasp the problem and finding it challenging to explain it clearly, so I have attached a picture depicting the issue. https://i.stack.imgur.com/E9Gzj.png My current approach involves using ratios of 100% and 100vw for element widths. D ...

An HTML editor that provides syntax highlighting for HTML code within PHP echo statements

Whenever we employ the echo function in PHP, the content within the quotes is considered as HTML. In certain HTML editors that I have tried, they simply highlight all of the HTML code in one single color, which can be a bit perplexing. Does anyone know o ...

Is it possible for you to simulate the shift key being pressed prior to the event execution?

Is there a way to allow the user to scroll left and right horizontally without having to hold the shift key down? I want to achieve this effect by setting the "shiftKey" variable to true even when it is not physically pressed. Any suggestions on how to ...

Contains a D3 (version 3.4) edge bundle chart along with a convenient update button for loading fresh datasets

I am looking to update my D3 (v3.4) edge bundling chart with a new dataset when a user clicks an 'update' button. Specifically, I want the chart to display data from the data2.json file instead of data1.json. Although I have started creating an u ...

Generate a new perspective by incorporating two distinct arrays

I have two arrays containing class information. The first array includes classId and className: classes = [ {classid : 1 , classname:"class1"},{classid : 2 , classname:"class2"},{classid : 3 , classname:"class3"}] The secon ...

concealing the date selection feature on the data picker

$('.year').datepicker({ changeMonth: true, changeYear: true, showButtonPanel: true, dateFormat: 'MM yy', onOpen: function(dateText, inst) { $("table.ui-datepicker-calendar").addClass('hide') }, onClos ...

Expanding the header in Ionic 3 with a simple click event

I have successfully implemented an Expandable Header in Ionic 3 following a tutorial from Joshmorony. The header expands perfectly on scroll, as you can see in this GIF: However, I am facing an issue where I want to expand the header on click instead of o ...

Executing a .sh script upon loading a webpage

Is there a way to automatically run a .sh file on webpage load to fetch a JSON file using cURL, without making it visible? I need to keep the API key confidential. ...

Combine multiple SCSS files located in various directories into a single CSS file by using NPM

In my project, there are SCSS files stored in a "static" directory. Additionally, I have application components located in a separate directory, each containing its own SCSS file. I am seeking a way to compile all of these SCSS files into a single .css fi ...

While reviewing my HTML code, I couldn't locate a particular line of code responsible for changing the display of my webpage. However, upon inspecting the element, I discovered that

<h2><a class="label label-info" target="_blank" href="http://www.avis.com.pk/"> Avis</h2> </a> <h4> <span class="label label-primary"> Rent A Car Service</span></h4> There is an Inspect Element image attach ...

An interactive selection tool for a website's navigation bar

Struggling to implement a dropdown menu for my navbar, none of the CSS methods I've tried seem to work. My current HTML code is as follows... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-t ...

`Is it possible to modify the background color of InputAdornment in Material-UI TextField?`

For the first 10% of the text field, one background color is used, while for the remaining 90%, another background color is applied. <TextField className={classes.root} type="text" placeholder="username" var ...

HTML code displaying a fixed message at the top of the webpage

I'm working on a web page that has a lot of content. I need to have a message always visible at the bottom of the browser window, even when scrolling. Can anyone help me achieve this using simple CSS, HTML, jQuery, or PHP? Thanks! ...

Conceal HTML elements from the bottom as new content is being added dynamically

I am currently working on a comments feed feature. By default, only the first four comments are displayed, with an option to show more when clicking the "show more" anchor. The issue I'm facing is that if new comments are dynamically added, the CSS hi ...