The challenge with positioning elements as fixed and setting overflow-y to scroll

After thoroughly researching this topic and reviewing various question & answer forums, including one on CSS overflow-x: visible; and overflow-y: hidden causing scrollbar issues, I am still unable to find a solution that works for my specific case. Even trying different overflow types on various parent elements has not yielded the desired result.

The Issue

I have a fixed menu with full height that contains numerous links. In cases where the browser window is not tall enough to display all the links, I need to implement scrolling within the fixed div to allow users access to all links.It should be a simple request.

How do I go about resolving this issue? Here's an example of the setup I am currently using: http://jsfiddle.net/mz9abf43/9/

UPDATE

This updated fiddle includes my complete code for better context. The visual appearance of my menu aligns with my requirements, but I specifically need vertical scrolling enabled if the screen height cannot accommodate the entire menu length. http://jsfiddle.net/mz9abf43/24/

Desired Outcome

The text lines between each link are intended to overflow to the right of the blue menu (as depicted in the image below) and concurrently permit user scrolling within the blue menu. Presently, achieving both tasks simultaneously proves challenging.

https://i.sstatic.net/BbYJl.png

My current structure consists of:

<div id="fixed">
    <nav>
       <ul class="menu">
         <div class="drop">
             <li>Link here</li>
             <li>Link here
                 <ul>
                    <div class="drop">
                        <li>Link here</li>
                        <li>Link here</li>
                    </div>
                 </ul>
             </li>
             <li>Link here</li>
         </div>
       </ul>
    <nav>
</div>

CSS Styling Used

#fixed {
        width:280px;
        position: fixed;
        top: 0;
        left: 0;
        bottom:0;
        z-index: 1000;
        background: #fff;
}

.menu   {
        padding: 0;
        margin: 0;
        position: fixed;
        z-index: 9998;
        top:0;
        bottom:0;
        left:0;
        background: white;
        width: 280px;

        /* ISSUES WITH SCROLLING - HOW CAN THIS BE FIXED? */
        overflow-y: scroll;
        overflow-x: visible;

}

.menu .drop {
            background: #fff;
            height: 100%;
            z-index: 0;
}

Answer №1

When you use position: fixed, the element cannot be scrolled. By setting it with top: 0, you are ensuring that the element is always at the top of the window, not the container. This means your ul will always be visible at the top of the window.

If your menu has a lot of elements and may require a scroll bar, it's better to use absolute positioning instead.

To make this change, simply replace 'fixed' with 'absolute' and remove the 'bottom: 0' property:

.menu   {
        padding: 0;
        margin: 0;
        position: absolute;
        z-index: 9998;
        top: 0;
        left: 0;
        background: white;
        width: 280px;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;                
    }

You can see the updated code in this FIDDLE.

Next, ensure that the height of your menu matches the content height by using jQuery:

var menuHeight = $('.content').outerHeight(true);
$('.menu').css({
    'height': menuHeight + 'px'
});

This calculates the height of your "content" container and sets it as the height of your menu.

You can also view an example in this JSFIDDLE2.

Feel free to comment if you encounter any issues, and I'll do my best to assist.

Answer №2

It is recommended to apply the box-sizing:border-box property within the .menu li a selector and set the width: 70%; in the .menu .drop selector.

.menu li a {
    color: #aaa;
    text-transform: uppercase;
    font-size:12px;
    padding: 8px 35px;
    display: inline-block;
    width: 100%;
    border-bottom: 2px solid #f0f0f0;
    box-sizing:border-box;
}

View Updated Fiddle

Answer №3

If I have misunderstood, please correct me.

Consider adding the following CSS:

.menu li a {
color: #aaa;
text-transform: uppercase;
font-size: 12px;
padding: 8px 35px;
display: inline-block;
width: 100%;
border-bottom: 2px solid #f0f0f0;
position: relative;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;

}

Additionally, you should remove the 'height:100%' property from the .menu .drop class to display the blue background properly.

Hopefully, this information is helpful.

Answer №4

Hope this satisfies your needs :)

<a style="float:right" href="http://www.asmhijas.com/">Check out my website!</a>


<div id="container1">
    <div id="container2">          
        <ul class="menu">
    <div class="drop">
        <li ><a href="#">Home</a></li>
        <li class="menu-item-has-children highlight"><a href="#" class="">HOVER ME!!</a>    
            <div class="drop">
                <ul class="sub-menu">
                    <li class="menu-item-has-children highlight"><a href="#" class="">2nd Level Page</a>
                        <div class="drop">
                            <ul class="sub-menu">       
                                <li class="highlight"><a href="#">3rd Level Page</a></li>
                                <li class="highlight"><a href="#">Another 3rd Level Page</a></li>
                            </ul>
                        </div>
                    </li>
                </ul>
            </div>
        </li>
        <li class="highlight"><a href="http://www.asmhijas.com/">Visit me</a></li>
        <li class="highlight"><a href="#">Link</a></li>
        <li class="highlight"><a href="#">Link</a></li>

    </div>
</ul>


    </div>
</div>

Custom styling goes here

.menu   {
        padding: 0;
        margin: 0;    
        z-index: 9998;
        top:0;
        bottom:0;
        left:0;
        background: white;

            -webkit-backface-visibility: hidden;
          backface-visibility: hidden;

    }

    .menu li.highlight {
        -webkit-transition: all .1s cubic-bezier(.77,0,.175,1) .1s;
        -moz-transition: all .1s cubic-bezier(.77,0,.175,1) .1s;
        -ms-transition: all .1s cubic-bezier(.77,0,.175,1) .1s;
        transition: all .1s cubic-bezier(.77,0,.175,1) .1s;
            -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
    }

    /* More CSS rules... */

 #container1{
    height: 100vh;
    width: 280px;
    overflow: hidden;

}

 #container2{
    height: 100%;
    width: 100%;
    overflow: auto;
    padding-right: 23px;


}
body{overflow:hidden}

View on JSFiddle

Answer №5

Attempt to establish overflow-x and overflow-y as hidden

hopefully this will be successful

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

Incorporate an additional javascript document into a VueJS component

What is the most efficient method to include Javascript files in Vue.js components? ...

Ways to determine if a Less file matches the compiled CSS file

Recently, I inherited a website that utilizes LESS for CSS pre-processing. My task involves updating certain styles; however, I am uncertain whether the former developers made changes to the LESS files and then compiled the CSS, or if they simply edited th ...

Using the Ruby on Rails redirect_to method

Imagine I have the following line in my controller: redirect_to "/sessions/attempt", provider: 5 Now, this is what my attempt.html.erb looks like: <h1>attempt</h1> <%= provider %> It's clear that this setup isn't functioning ...

challenges in populating arrays with Javascript

After performing certain actions, I have generated an array of data. Upon submitting the page, the control will redirect to the second page where I need to populate the array data into tables using Javascript only. The problems I am currently facing are: ...

Tips for implementing an HTML modal with AngularJS binding for a pop up effect

As a beginner in AngularJS, I am facing a challenge. I have an HTML page that I want to display as a pop-up in another HTML page (both pages have content loaded from controllers). Using the router works fine for moving between pages, but now I want the s ...

Customizing nested tables in your HTML email

When creating an HTML email template with nested tables for maximum email client support, the question arises about using inline styling. Should the style always be applied to the lowest level td, or is it possible to apply it to a parent table or td? For ...

Text positioned in a fixed location

How can I ensure that the main content stays on the right side of the sidebar without adding margin-right? Currently, the sidebar is being covered by the body content due to its fixed position. Is there a solution to prevent this issue? .App { displa ...

Tips on accessing a particular value from an HTML header

My current task involves using selenium to extract request headers from a web page. However, I am facing an issue where all request headers are being printed out, whereas I only need one specific value from them. Despite searching online, I have been unabl ...

Using the <ins> element to push content into a separate div lower on the webpage

My text inside the <p> element is being pushed down by the presence of the <ins> tag. Removing the <ins> tag from the DOM using developer tools results in my text returning to its expected position. main { max-width: 1000px; ma ...

Strange glitches and slow loading problems plaguing website. (GoDaddy)

TackEmporium.com Lately, I have been revamping my website, which was originally given to me by a friend. I have been making slight adjustments to update its appearance while keeping its classic look with enhanced resolution and cleaned-up HTML5 code. Rec ...

What is causing my function to execute twice in all of my components?

One issue I am facing is that I have created three different components with routing. However, when I open these components, they seem to loop twice every time. What could be causing this behavior and how can I resolve it? For instance, in one of the comp ...

Can someone describe the cell phone symbol displayed in Google search results?

As I work on developing a mobile-friendly version of my website, I have noticed the presence of a mobile icon in Google search results. I am curious to learn more about what this mobile icon signifies and how I can effectively utilize it for optimizing m ...

There was an issue in the v-on handler that resulted in an error: "TypeError: The property '$createElement' cannot be read because it is undefined."

I am encountering an issue with some basic input/output code. The task at hand is to receive input in Newick format and use it to create a tree. However, I am struggling to even receive the input correctly. Below is the HTML code snippet I am using: ...

Creating a JavaScript-powered multi-department form: A step-by-step guide

Is there a way to maintain the form displayed on a webpage created in HTML5 and JavaScript for logging calls across three different departments? With buttons assigned to each department, clicking on them reveals the respective HTML form. That said, every t ...

jQuery Hover Event Handling

I'm encountering an issue with syncing hover effects in two separate tables. Oddly, the first part of the function works fine on its own. However, when I add the second part, it breaks the first part without any errors. I refrained from including it ...

Is it better to use on click instead of href for this task?

I have a limited number of items in my navigation bar, both vertically and horizontally. Each item corresponds to a different page. I've come across several articles discussing href attributes and the various opinions on their usage, particularly in H ...

Functions for handling success and error events in jQuery

On a webpage, I've implemented a form for users to input an image URL that will serve various purposes. I'm currently developing an ajax function to verify if the provided URL is indeed associated with an image file. Here's what I have so fa ...

Looking for a way to trigger PHP mail when a form is submitted rather than on page load without relying on If...POST conditions?

I have a PHP mail code that successfully sends an email message when the page loads, but I need it to send on form submission on the same page. I have searched for solutions, but due to the specific code I am using, I couldn't figure it out. This pag ...

How can I utilize JavaScript to seamlessly loop through and display these three images in succession?

My current code is HTML, CSS, and JS-based. I am looking to design three of these div elements that appear and hide in a loop every 3-5 seconds. After the first run, I want the execution to repeat continuously. How can I modify my code to achieve this func ...

What is the best way to unravel the web of Django URLs within my project?

As a newcomer to django, I created a project and app by carefully studying YouTube videos and the Django documentation. I implemented HTML pages for sign in, sign up, and business sign up respectively. project/urls.py from django.contrib import adm ...