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

Differences in layout design when using floats and display: table between Chrome and Firefox can affect the visual appearance

Try out this link on JS Fiddle: https://jsfiddle.net/7p81bnto/2/ Here's the HTML code: <body> <main> <div> <div style=" height: 50px; width: 200px; ...

Navigating dropdown list items using the keyboard in TypeScript is a breeze

I've encountered a bug while working on my open-source project. The issue is with navigating the dropdown list items using the keyboard (arrow key/tab). I have implemented the keyboard-navigation logic, but I'm unsure of how to make it work corre ...

My jquery filter is not functioning properly

I need help making the active class work on each category when clicked, shifting to the next one. I've tried implementing it but no luck so far. $(document).ready(function() { $('.list-inline-item').click(function() { const value = ...

HTML and JavaScript code to desaturate or grayscale image rollovers without the need for additional image duplicates or sprites

Is there a way to achieve grayscale to color image rollover effects without duplicating images or using sprites? I'm looking for an alternative technique that can accomplish this. Any suggestions on how to implement it? ...

The image is failing to display in the CSS

As a beginner in the world of CSS and HTML, I encountered an issue where my background image is not showing up. Here's the code snippet that I have: ... <style type="text/css"> #header_contain{ width:935px; height: 135px; ...

Detect when a user's mouse is hovering over an iframe and escape the iframe accordingly

When the iframe window is visible, there are no issues. However, if the iframe window is set to 0px X 0px in order to hide it while still loading, consider redirecting the iframe or not displaying it at all. In case something is loaded within an iframe or ...

Organizing an angular expansion panel

I am currently dealing with an expansion panel that has a lot of content. The layout is quite messy and chaotic, as seen here: https://ibb.co/Y3z9gdf It doesn't look very appealing, so I'm wondering if there is a way to organize it better or ma ...

Adjust text to fit within a specified height container automatically

Is there a way to make text resize automatically based on the height and width of its container? I've looked at similar questions but none seem to provide the right solution for me. I tried using fitText, but it doesn't take the container's ...

Customize the Position of Icons in Material UI

I am looking for guidance on how to position my components within an image using Material UI. Specifically, I want to move my heart component to the top right corner of the image and place the ratings at the bottom. import image from "../../Assets/pic ...

Starting a Fresh Chapter Upon Successful Form Submission with PHP

I am utilizing PHP to control form elements. If the elements are invalid, I display an error message below them. My issue arises when all form elements are valid, but the page does not redirect to the desired destination page. Instead, it displays an empty ...

There is a single div sandwiched between two others, with each of the surrounding divs reaching the edge of the browser

Require a small space between the middle div and the two on each side. The middle bar should have a fixed width. Here is my attempt so far, but it seems messy: <!DOCTYPE html> <html> <head> <style> #container { width: auto; ...

Creating vibrant row displays in Vue.js: A guide to styling each row uniquely

I am not a front-end developer, so Vue and JS are new concepts for me. Currently, I am working on an application for managing sales. One of the components in my project involves displaying invoices in a list format. To make the rows visually appealing, I ...

Placing buttons on top of a video within a div container

I am facing a challenge with implementing custom controls on a video embedded in my webpage. I have tried setting a div to absolute position for the buttons, but they are not clickable. Is there a way to achieve this without using jQuery? I need the butto ...

Replacing an array in Perl with the contents of a SQL database: A step-by-step guide

Update: (Check Revised Code at the bottom) The code is now functioning properly to retrieve data from 2 databases with some additional cleaning required. However, I'm facing a challenge where the code previously used: next unless $currentuser ~~ @las ...

HTML5 allows users to play a extended video for a set duration without the need for any video editing. Users are encouraged to utilize any approach

I have a video file named myvideo.mp4 that is 3 minutes long (or any length). <video width="320" height="240" controls="controls"> <source src="myvideo.mp4" type="video/mp4"> </video> Is there a way to play this myvideo.mp4 for only 20 ...

Having trouble displaying an image on a subpage in HTML

I've been struggling to display an image on one of my subpages using HTML. I suspect that the issue lies in how I am referencing the image file in the code. The image file is named crab.jpg and it is stored inside the pics folder within the Websites d ...

Does defining the width and height of images go against the principles of material design?

Currently, I am immersed in a project utilizing material design. In this context, I find myself contemplating the size of an image that has been hard-coded as (200x200). I am curious to know if this approach aligns with the principles of material design. ...

Exploring the functionalities of jQuery and Local Storage: Understanding the Selector's various states

I am currently developing a new feature for font customization on a website. The drop-down menu offers several font options to choose from. When a user clicks on one of these options, the following code is executed: jQuery(function($) { if (localStorage.g ...

execute a different function once the animation has finished running with the .bind

When attempting to detect the completion of a CSS animation in order to remove a class, I encountered an issue where using .bind causes the animation end event to trigger even for the other function. You can view the complete code here. How can I ensure ...

JavaScript form with radio buttons

I'm completely new to JavaScript and I'm attempting to create a basic script that will show one form when a radio button is checked, and another form when the second radio button is clicked (with no form displayed when neither is selected). I kno ...