1

My question is similar to CSS: How to have position:absolute div inside a position:relative div not be cropped by an overflow:hidden on a container.

I have a very long vertical menu that shows a submenu on hover. I want to make the menu fixed and 100% height on my page and use a scroll bar to scroll menu items. I will use jquery slimScroll to show the scroll bar which needs the parent container to have overflow: hidden.

The issue is that the submenu will not show over the parent container if it has overflow: hidden. Html code:

<div class="scrollable">
<ul class="menu">
    <li>Menu
        <ul class="submenu">
            <li>Submenu</li>
            <li>Submenu</li>
            <li>Submenu</li>
        </ul>                   
    </li>
    <li>Menu
        <ul class="submenu">
            <li>Submenu</li>
            <li>Submenu</li>
            <li>Submenu</li>
        </ul>                   
    </li>
    <li>Menu
        <ul class="submenu">
            <li>Submenu</li>
        </ul>                   
    </li>
    <li>Menu
        <ul class="submenu">
            <li>Submenu</li>
            <li>Submenu</li>
            <li>Submenu</li>
        </ul>                   
    </li>
    <li>Menu
        <ul class="submenu">
            <li>Submenu</li>
            <li>Submenu</li>
            <li>Submenu</li>
        </ul>                   
    </li>
</ul>

CSS code:

 /* this needs to have a fixed position */
.scrollable {   
    /* If i remove the fixed position the ul's will go outside */
    position: fixed;
    top: 0;
    left: 0;

    overflow: hidden;
    /*
    overflow-y: scroll;
    overflow-x: hidden;
    overflow-x: visible;
    */    
    width: 100px;
    height: 100px;
    border: 1px solid #ff0000;
    padding: 10px;
}
ul {
    margin: 0; 
    padding: 0; 
    list-style-type: none;
    position: absolute;
}
li {  
    width: 100px;  
    background-color: #dddddd; 
    line-height: 50px;
    height: 50px;
    border-bottom: 1px solid #fff;
    display: block;
    /* even if I set position to absolute, which messes the design, the submenu wont show outside */
    /* position: absolute; */
}
.submenu { 
    display:none; 
    margin: -45px 0 0 70px;
    border: 1px solid #000;
    position: absolute;
    z-index: 100;
}
.menu li:hover .submenu {
    display: block;
}

I have an example of striped html and css here jsfiddle.

Is there a way to show the submenu over the container with overflow:hidden?

Community
  • 1
  • 1
AndreiV
  • 11
  • 1
  • 3

1 Answers1

0

Please check this link and let me know this is what you are looking for.

css

ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
}
.scrollable {
    position: fxied;
    top: 0;
    left: 0;
    overflow: hidden;
    width: 100px;
    height: 100px;
    border: 1px solid #ff0000;
    padding: 10px;
}
ul.menu > li {
    color: #ff0000;
}
li {
    background-color: #dddddd;
    line-height: 50px;
    height: 50px;
    border-bottom: 1px solid #fff;
    display: block;
}
.submenu {
    width: 200px;
    display:none;
    margin: -45px 0 0 70px;
    border: 1px solid #000;
    position: absolute;
    z-index: 100;
}
.menu li:hover .submenu {
    display: block;
}
ilmk
  • 599
  • 1
  • 9
  • 19
  • It's close, but one issue remains, I need to have a container to be scrolled. In your case it will be the ul that will have a scroll inside. When I scroll down the menu list and put the mouse over the menu item the submenu will be way down, my guess, because it keeps the previous scrolling position. I have updated the fiddle a bit: [link](http://jsfiddle.net/JZe43/15/). Scroll the menu items all the way down and hover a menu to see what happens. – AndreiV May 05 '14 at 18:07