Tips for enabling an element to exceed the bounds of a scrollable container

I am facing an issue with my menu where it has grown in size, making it necessary to have a scroll function for easier navigation. I have successfully implemented the scrolling feature.

However, within this menu is a submenu that should extend out to the side. I have also achieved this without any problems.

The challenge arises when trying to combine both functionalities - once the menu becomes scrollable, the submenu gets clipped, particularly in Chrome.

What are some effective solutions (aside from less ideal ones) to ensure that the submenu remains visible even when the main menu is scrollable?

Below is a code snippet illustrating the scenario:

function makeScrollable(){
    var outer = document.getElementById("outer");
    outer.style.overflowY="auto";
}

ul{
    list-style:none;
    border: 1px solid black;
    background-color: grey;
    padding: 10px;
}

#outer{
    position: absolute;
    right: 10px;
    max-height: 80px;
}
#inner{
    position:absolute;
    right: 90%;
}
li{
    display:block;
}

  • one
  • two
    • alpha
    • beta
    • gamma
  • three
  • four
  • five
  • six

Answer №1

To put it simply, having both functionalities on the same element is not possible. Popular libraries like Bootstrap and Material Design tackle this by dynamically placing sub-menus outside of their parent elements through a series of steps:

  • Calculating the position of the sub-menu based on the parent element's .getBoundingClientRect() values
  • Attaching the sub-menu to the <body> element
  • Disabling scroll on the <body> while the sub-menu is open to prevent any movement of the parent element under the fixed positioned sub-menu.

A potential issue lies in attempting to apply desktop conventions to touch devices. It's crucial for menus on touchscreens to have sufficient space for tapping without concerns about missing the target. Generally, a menu item should be at least 45px tall.

On touch devices, there is no harm in opening the menu across the entire screen width. Most users are unconcerned with viewing a portion of the page beneath a narrower menu.

Sub-menus can either function as accordions within the main menu, differentiated by slight changes in the background, pushing subsequent parent elements downwards. Alternatively, they can act as an additional layer of menu over the main one, possibly featuring a 3D entrance/exit animation. Return to the top level can then be achieved by closing the sub-menu, tapping a visible close button, or swiping in the direction from which the menu originated.

This brief overview only touches on some essential principles of mobile design. Further exploration of this topic is highly recommended. A valuable resource to begin with would be the Material Design Guidelines provided by Google.

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

What is the best way to use HTML and CSS to center images and headings on a webpage?

This task is really testing my patience... I'm attempting to create a layout that resembles the following: Logo img|h1|img The horizontal lines flanking the subtitle serve as a visual guide, like this --- Subtitle --- Below is the snippet of H ...

Having trouble displaying the HTML page in Django? Encountering a NoReverseMatch Error?

I have successfully created and integrated a django app into my project. Now, I am attempting to include another HTML page titled "About" to the existing setup. I have added the about page within the home app. View image of code snippet here Below is the ...

What is the best way to delete a CSS class from a specific element in a list using React?

I need to implement a functionality in React that removes a specific CSS class from an item when clicking on that item's button, triggering the appearance of a menu. Here is my code snippet. import "./Homepage.css" import React, { useState, ...

Identifying whether a Alphabet or a Digit has been Pressed - JavaScript

I understand that it is possible to detect if a key has been pressed and identify which key was pressed using JavaScript. In order to check if a key is down or pressed, jQuery can be utilized with ease: $( "#some id" ).keydown(function() or $( "#m" ). ...

Unable to access 'read more' link in WordPress post - seeking solution

Is there a way to move the "read more" link to the end of the post on my blog homepage? Currently, all the content of the post is displayed on my homepage. I want to restrict the characters shown and have the link at the end. Thank you! ...

Notification Click Event for PWA Service Worker

I am attempting to display a notification and trigger an action when it is clicked. try { navigator.serviceWorker.getRegistration() .then(reg => { reg.showNotification("Check out the video clip!", { body: "Cl ...

Guide on generating a dynamic loop in JavaScript using the group name as a variable

I have been attempting to organize a group, dynamically ungroup it, and then create a loop with each element of the group. Despite reviewing multiple examples, I have not been able to solve the following issue: The grouping is done based on the "tipo" pro ...

What is the process for triggering property decorators during runtime?

Wondering about dynamically invoking a property decorator at runtime. If we take a look at the code snippet below: function PropertyDecorator( target: Object, // The prototype of the class propertyKey: string | symbol // The name of th ...

What is the proper application of counter-reset when utilizing CSS counters to automatically number headings?

In my quest to automatically number headings with multiple levels of hierarchy in an HTML document using CSS, I have encountered various examples online that heavily rely on counter-reset. However, despite testing it in different configurations, I haven&ap ...

The unfortunate error of 'MODULE NOT DISCOVERED' has arisen, as the module cannot be located

Currently working on resolving the pathing issues: This is how my folder structure appears: /www/html/ /database/ databaseConnection.js /scripts/ LoginPageScript.js server.js index.html In the database js file, there is the following code snippe ...

Dynamic jQuery backstretch feature: automatic image cycling and reversing

I am currently using backstretch on my website and attempting to create a continuous loop of the moving image by automatically shifting it from left to right and back. However, I am facing difficulties as the background only moves in one direction. I am se ...

Utilizing ajax for fetching a data table

I am new to using ajax and have successfully retrieved data from a table. However, I am now trying to pull in an entire data grid but not sure how to achieve this. In my index.php file, I have the following code: <html> <head><title>Aj ...

Testing asynchronous functions with Mocha

Currently, I am in the process of developing a node wrapper to interface with an external api. One particular challenge I am facing is testing the asynchronous functionality of the createJob method. Provided below is the test case code: api_key = "test_0d ...

How can you compare input text to the input value attribute using jQuery?

Consider this scenario: the page displays the following input element... <input class="textInput error" id="accountMailaddress" name="user[email]" size="30" type="text" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail=" ...

What is the best method to create random coordinates that fall outside of the circle located within a rectangular area?

Suppose the following scenario: A rectangular area with dimensions length l and breadth b A circle with a radius r The circle is positioned inside the rectangular area as depicted in the image below Check out the image here - Red areas show expected even ...

Locate items within a nested array of objects

I need to extract a specific object from a JSON array with nested objects by using the key name. I've attempted various methods but haven't found a generic solution yet. let data = {"role":"http://www.icai.org/xbrl/taxonomy/role/in ...

Transmitting the User's Geographic Location and IP Address Securely in a Hidden Input Field

I'm looking to enhance my HTML form by retrieving the user's IP address and country when they submit the form. How can I achieve this in a way that hides the information from the user? Are there any specific elements or code additions I need to ...

What is the best way to create a navigation link in PHP along with forms?

If the login credentials are correct, I will be directed to the member page. If not, I should remain on the same page. I am struggling with how to create a link to another page. I have come across some suggestions involving headers, but I am still unsure o ...

Using `babel/register` does not seem to be functioning as expected

I am working on an isomorphic app built in ES6 on the client side using the Babel transpiler. I would like my express server to also utilize the same ES6 syntax as the client code. Unfortunately, attempting to use require('babel/register') has n ...

CORS request results in unsuccessful cookie setting in browsers except for Firefox where Set-Cookie header is detected; notably, Chrome does not show the header

I'm experiencing an issue with setting cookies from a NodeJS server to the client using JQuery and AJAX. Despite seeing the Set-Cookie headers in the response, the cookies are not showing up in the document.cookie string. I would greatly appreciate it ...