Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position fixed and overflow-y:scroll issue

I have read this question & answer: CSS overflow-x: visible; and overflow-y: hidden; causing scrollbar issue as well as a bunch of other conflicting use cases. I've tried applying different overflow types to different parents also. Nothing seems to get my use case working.

My Case

I have a full height fixed menu that will contain lots of links so if a browser isn't high enough to show them all I'd like to allow the user to scroll within the fixed div. Not a bold request.

How do I work around this issue, here's an example of the setup i'm using: http://jsfiddle.net/mz9abf43/9/

UPDATE

This is the updated fiddle with my full code for context, this is exactly how I want my menu to look but I just want to allow vertical scrolling if the screen height is smaller than the length of the menu. http://jsfiddle.net/mz9abf43/24/

Expected Output

The lines between each link should overflow to the right of the blue menu (like the image below) AND also allow the user to scroll within the blue menu. Currently I can only do one or the other.

enter image description here

My structure is:

<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>

My CSS is

#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;

        /* THIS IS NOT WORKING - HOW CAN I GET THIS WORKING? */
        overflow-y: scroll;
        overflow-x: visible;

}

.menu .drop {
            background: #fff;
            height: 100%;
            z-index: 0;
}
like image 617
egr103 Avatar asked Oct 01 '15 08:10

egr103


People also ask

How do I fix scrolling position?

To make an element stick to the screen when you are scrolling, select it and just click the Fix Position When Scrolling checkbox. Select the artboard, set a Vertical Scrolling and set a value for the Viewpoint Height that's lower than the height of the entire artboard.

What is overflow-Y scroll?

The overflow-y property specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the top and bottom edges.


2 Answers

Position:fixed can't be scrolled. When you set it with top:0 You are positioning the element to be always at the top of the window (not the container) and I'm afraid that's exactly what you will see, your ul always at the top of the window.

Probably better to use an absolute positioned if your menú may get many elements so you will get scroll bar on the body.

so as a starting point is You just need to chnage fixed for absolute and delete the bottom:0property:

.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;                
    }

as in this FIDDLE

You now just need be sure the height of this menu is as "tall" as your content so it will fill all your window height. You can use a basic jquery:

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

where you calculate the height of your "content" container and add it as a css property to your menu:

JSFIDDLE2

Note: I made this answer from my comments on the question. If you find any other problem feel free to comment here and I'll try my best to help (if I know how).

like image 56
Alvaro Menéndez Avatar answered Oct 04 '22 21:10

Alvaro Menéndez


You should use box-sizing:border-box in .menu li a and make width: 70%; in .menu .drop.

.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;
}

UPDATE Fiddle

like image 24
Mukul Kant Avatar answered Oct 04 '22 20:10

Mukul Kant