Activate the scroll bar for a container with a fixed position

I have a sidebar with fixed positioning that contains a list of links:

<nav id="fixedNav">
    <div class="anchors">
        <ul>
          <li><a href="#">test 1</a></li>
          <li><a href="#">test 2</a></li>
          <li><a href="#">test 3</a></li>
          <li><a href="#">test 4</a></li>
          <li><a href="#">test 5</a></li>
          <li><a href="#">test 6</a></li>
          <li><a href="#">test 7</a></li>
          <li><a href="#">test 8</a></li>
          <li><a href="#">test 9</a></li>
        </ul>
     </div>
     <div class="button"></div>
</nav>

#fixedNav {
    position: fixed;
    left: 0;
    top: 70%;
    z-index: 1000;
}
#fixedNav div {
    float: left;
}
#fixedNav .anchors {
    padding: 1em 1em;
    border: 1px solid #ddd;
    border-left: 0;
    overflow-y: scroll;
}
#fixedNav .button {
    width: 50px;
    height: 50px;
    border: 1px solid #ddd;
    border-left: 0;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

You can view the code in action at https://jsfiddle.net/850bfnb1/

My issue is that I want to add a scrollbar to the sidebar because not all the links are visible due to its fixed position, but for some reason the scrollbar appears but does not work properly. Any ideas on how to fix this?

Answer №1

Give this a shot:

height: 100%;

Add the above code to #fixedNav .anchors, so that Anchors fills its parent properly.

bottom: 0;

Next, apply the following to #fixedNav to ensure it stays at the bottom of the screen. Then, insert:

#fixedNav {
    position: fixed;
    left: 0;
    top: 70%;
    bottom:0;
    z-index: 1000;
}
#fixedNav .anchors {
    padding: 1em 1em;
    border: 1px solid #ddd;
    border-left: 0;
    overflow-y: scroll;
    height: 100%;
}

Here is a link to see it in action!

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

Does Blazorise support the Material .figure-is-16x16 class?

While Blazorise supports the .figure-is-16x16 class, I have noticed that when using it in Material, it does not work by default. I am curious if the Material version of Blazorise supports this class or if there is another related class available. Current ...

Creating a Map Using HTML and JavaScript

My current project involves creating a simple map that can be moved with mouse drag functionality, featuring images such as islands. I have successfully retrieved the mouse position by declaring variables posX and e.clientX, as well as for e.clientY. Howe ...

Malfunction detected in JavaScript shopping cart functionality

Trying to implement a functional shopping cart on a webpage has been a challenge for me. I've encountered issues in my JavaScript code that are preventing the cart from working as intended. As a newbie to JavaScript, I'm struggling to pinpoint th ...

Change a div to scroll vertically instead of expanding to accommodate its content

I am facing an issue with the layout I have created. It consists of a scrollable list of items in the center, with additional content above and below it in a column. The challenge is to make the list occupy all available empty space within the column witho ...

Create two floating divs that adjust their height dynamically to be equal

Situation: I have a container with two direct children, known as "left" and "right". The height of the "left" child should never exceed the height of the "right" child. However, the "right" child can extend beyond the height of the "left" child. I am stru ...

Bring about a transformation in the background color of a form upon losing focus after inputting text

Just to clarify, everything here is client side and not web-based at all. My goal is to change the form boxes to green after losing focus when text has been inputted. The form boxes initially start out white, turn purple on focus, and I want them to turn ...

Firefox fails to render SVG animation

Currently, I'm attempting to incorporate this unique animation into my website: http://codepen.io/dbj/full/epXEyd I've implemented the following JavaScript code in order to achieve the desired effect: var tl = new TimelineLite; tl.staggerFromTo ...

What is the reason behind adding a dot or period in the ID of an HTML element?

What is the purpose of inserting a dot or period in the id of an HTML element? Are there any additional benefits in terms of coding languages? <div id="PAT.TID" class="lineHeight frmData">Headset, e.g. Bluetooth headset, for mobile device has config ...

Position SVG element within a Bootstrap 4 row

Is there a way to center align both an icon (<svg>) and text within a container with a small spacing between the two elements? | ICON TEXT | Here is a JSBin link for reference: https://jsbin.com/tatomas/edit?html,css,output I have Bootst ...

The lower border is unresponsive in the CSS/HTML code currently in use

Currently diving into the world of Web Development, I find myself tackling the CSS part. My latest challenge involves adding a bottom border to an element, but no matter what I try, the border just won't show up. I've scoured resources for soluti ...

Can 'fr' units be used in the `calc()` function of CSS?

In this particular scenario, the query arises whether the CSS calc() function extends its support to the fr unit as presented in the below example? .sample-grid { --main-fr: 60fr; grid-template-columns: var(--main-fr) 1rem calc(100 - var(--main-fr ...

When hovering over, my text and image shift to the left in a strange and abnormal manner

Recently, I made a small code addition to an existing one in order to display text below an image and have the text highlighted in blue on mouse over. Everything seemed to be working fine until I noticed that on mouseover, the text and image shifted to the ...

"The Divine Chalice" trichotomy format employing flexbox styling

My goal is to create a three-column layout known as the "holy grail" using the new display: flex syntax, as outlined in this ALA article. The setup requirements are: A header and footer with three columns in between The outer columns have fixed widths T ...

Is it possible for a CSS menu with border to slide off the screen?

https://i.sstatic.net/bBbkU.png How can I create a CSS menu with borders that do not overflow off the page when using margin:0; I am trying to add a border to my CSS links without them overflowing on top of the page. I have imported my custom.css file in ...

What is the best way to extend this dropdown menu to span the entire width of the page?

My Bootstrap 5 megamenu needs all the dropdown menus to span the entire page width and be in the same position, similar to this page. How can I make the dropdown menus larger? Which Bootstrap class should I modify? I've attempted to make changes, bu ...

Tips for aligning a text box and button side by side in HTML

Can someone help me? I am trying to keep the text box and button in the same line, but they keep appearing on separate lines: <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" da ...

Resize the shape of an image's polygon

Is there a way to independently scale a specific polygon of an image on hover? For example, I have a world map and I would like to enlarge a country when hovering over it, then return it to its original size when no longer hovering. I am familiar with us ...

Utilizing HTML/CSS3 in conjunction with a WebView to resize an image to fit the screen might result in a brief moment of a white screen

I'm currently using an Android WebView to load a local HTML file that scales an image as the background. However, I encountered a brief white screen flash before the image loads when launching the activity with the WebView. Though it's not a majo ...

Joomla, Enhancement for iFrame Sizing

A close associate who runs his own construction business has asked me to create a website for him using Joomla. I have successfully implemented most of the features he wanted, but now I need some assistance. He wants to showcase references written about hi ...

What's the best way to conceal the navbar while attempting to print the page?

Currently, I am working on developing an application for my school project. One of the features is an invoice sheet with a print option. However, when I try to print by clicking the button or using ctrl+p, the navbar appears in a chaotic and disorganized m ...