Unable to move the content inside a fixed container by scrolling

Having difficulties with a menu layout where the parent container spans across the entire site and a div contains the actual content. Everything looks fine on larger screens, but on mobile devices, it's challenging to display all the content.

I've set up a jsfiddle at http://jsfiddle.net/89xyzsfz/ to demonstrate the issue with a working example along with the necessary js and css. On mobile devices, only parts of the content are visible, and scrolling through them is not possible.

The code snippet below highlights the key components:

            <div class="hiddenMenu jsMenu">
                <div class="menuContainer jsMenuContainer">
                    <h3>Menu content</h3>

                    <ul>
                        <li><a href="#item1">Item1</a></li>
                        <li><a href="#item2">Item2</a></li>
                        <li><a href="#item3">Item3</a></li>
                        <li><a href="#item4">Item4</a></li>
                        <li><a href="#item5">Item5</a></li>
                        <li><a href="#item6">Item6</a></li>
                        <li><a href="#item7">Item7</a></li>
                        <li><a href="#item8">Item8</a></li>
                        <li><a href="#item9">Item9</a></li>
                    </ul>
                </div>

                <div class="menuBackground jsMenuBackground"></div>
            </div>
  • hiddenMenu encompasses the entire menu. Initially, the menu is hidden and becomes visible upon clicking an element with the css class jsMenuButton.
  • menuContainer houses the scrollable content when parts are out of view on smaller devices.
  • menuBackground is utilized for background design purposes when displaying the content, providing no other specific functionality.

Answer №1

Revise your css code for .hiddenMenu .menuContainer as shown below:

.hiddenMenu .menuContainer {
  position: relative;
  margin: 0 auto;
  text-align: center;
  z-index: 12;
  height: 100%;
  overflow: auto;
}

The .menuContainer should enable scrolling of menu items, hence requiring the use of overflow:auto;, height:100%, and a change from absolute to relative positioning.

http://jsfiddle.net/89xyzsfz/5/

I trust this information proves useful!

Answer №2

Make a Simple Adjustment to Your Code with This CSS Solution. The overflow is clipped, but a scroll bar is added for viewing the remaining content.

.hiddenMenu {
    display: none;
    height: 100%;
    left: 0;
    position: fixed;
    top : 0;
    width: 100%;
    z-index: 10;
    overflow:scroll;
}

Understanding Overflow Values

visible: Content extends outside its box without clipping. The default property value.

hidden: Content that overflows will be hidden.

scroll: Similar to 'hidden', but users can navigate through the hidden content.

auto: If content exceeds its box, it is hidden and users can scroll to view the rest of the content.

initial: Default value - visible.

inherit: Sets the overflow to match its parent element's value.

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

Adding space around images in JavaFX

Just a quick question. I'm wondering if there is a way to apply padding to an ImageView using CSS in JavaFX. I've attempted insets, padding, and other methods with no success. Alternatively, can the same effect be achieved with a Text Object? ...

Fully conceal a DIV while the webpage is loading

Following the header, I've implemented a hidden div with a height transition that can be activated by a button. However, there seems to be an issue where the browser displays the content of the div while the page is loading and then hides it afterward ...

Email attachments not working in Node Mailgun

I am facing an issue with my code that is designed to send emails using Mailgun in Node. The code functions as expected and sends the email successfully; however, it fails to attach the specified files. // pdfA and pdfB are both buffers defined earlier le ...

Employing an assortment of data points within a manufacturing facility

Currently, I have a factory that utilizes a JSON file wrapped in a $http.get request for testing purposes. However, this approach is not suitable when working within a SharePoint environment where JSON files are restricted. In the end, the goal is to integ ...

Interactive JS chart for visually representing values within a preset range in Vue.js

I was in need of a custom JavaScript chart specifically designed to display a value within a specified upper and lower limit. The main application for this would be illustrating the current stock price between its 52-week high and low ranges. It was essent ...

I'm having trouble with Gutters GX and GY not functioning properly in Bootstrap, HTML, and CSS

I attempted to incorporate gutters into my Bootstrap grid layout, however, they are not showing up as expected. I am following the guidelines provided on the Bootstrap documentation, but for some reason, the gutters are not appearing. <!DOCTYPE html> ...

Navigating between pages using the ExpressJS and Angular 1 routing system

Can someone help me troubleshoot an issue I'm having with my Express API and Angular front-end? Whenever I try to access the /about route, it keeps defaulting back to index.html and displaying a 404 error message. Can you take a look at my code and pi ...

Guide to Changing the Value of a Textbox Using Form jQuery

For instance: <form id="example1"> <input type="text" name="example_input"> </form> <form id="example2"> <input type="text" name="example_input"> </form> In the code above, both text boxes have the same name. H ...

Generate a fresh array from the existing array and extract various properties to form a child object or sub-array

I am dealing with an array of Responses that contain multiple IDs along with different question answers. Responses = [0:{Id : 1,Name : John, QuestionId :1,Answer :8}, 1:{Id : 1,Name : John, QuestionId :2,Answer :9}, 2:{Id : 1,Name : John, QuestionId :3,An ...

The connection between an HTML form and PHP is not being established

variable-passing.php `<form method="post" action="variable-catching.php"> <input type="text" name="name1"/><br/> <input type="text" name="name2"/><br/> <input type="text" name="name3"/><br/> <input type="te ...

Trouble Deciphering JSON Array Using Eval Function

I'm facing an issue with two files in my project - one is a PHP file containing an array that is echoed using json_encode, and the other is a JavaScript file containing various functions for a webpage. One particular function in the JavaScript file is ...

The addition of a cancel swipe feature to an HTML5 eBook is causing the text input field for note-taking to malfunction

I am currently working on the development of a process to create HTML5 based eBooks for both desktop and mobile use using Adobe InDesign and exporting them with a plugin called In5. This plugin allows for the incorporation of html, css, and javascript duri ...

Step-by-step guide on replicating a website along with its CSS styles and scripts

I've been exploring the idea of cloning a webpage, such as Instagram's login page, along with its CSS elements and JavaScript, to use locally. Basically, I want to duplicate the login page and host it on my test server in a way that allows it to ...

Retrieve specific information from a JSON file and save it in an array using Node.js/JavaScript

My goal is to extract all log details from a JSON object, but the issue is that the key for each user is constantly changing. let userJsonObject = { "user_1":{ "id":"user_1", "log":"de-data", ...

Jquery for controlling the navigation menu

I'm new to JavaScript and facing 3 challenges: 1. When I click on the parent <li>, the correct content of the child <sub> does not show up. Each category like "colors, shapes, sizes" should have corresponding child categories like "green, ...

Tips for handling the accent mark (diacritic mark)

My primary language is Spanish, which means I use accent marks quite frequently (á, é...). When I need to type them out, I resort to using &aacute;, &eacute;, and so on. However, I'm facing an issue when trying to compare two sentences in m ...

Why doesn't the 'Range' input type slide on React.js documentation, but it does on CodePen?

Can someone help me figure out why my range slider is not working in my React app? I copied the code from Codepen where it works fine, but in my app, it's not functioning properly. The slider doesn't slide when dragged and clicking on it doesn&a ...

Running the NPM build command results in an error specifically related to an HTML file

I encountered an issue in my AngularJS application when running the command: npm run build -- -prod The error message I received was: ERROR in ng:///home/directoryling/appname-play.component.html (173,41): The left-hand side of an arithmetic operation ...

Step-by-step guide on dynamically fetching additional images from a directory using php, jquery, and ajax

I have a scenario where I have multiple folders, each containing up to 20 images. On my HTML page, I want to display the first 5 images and provide a "click to view more" option to show the remaining 15 images when clicked. Currently, the issue I am facin ...

What is the best way to ensure that a mapped type preserves its data types when accessing a variable?

I am currently working on preserving the types of an object that has string keys and values that can fall into two possible types. Consider this simple example: type Option1 = number type Option2 = string interface Options { readonly [key: string]: Op ...