Multilevel Nav Menu not showing 3rd level

2019-02-18 22:13发布

问题:

the third level of my menu doesn't show up when hovering the 2nd level. I know that this is because overflow:hidden is styled on the 2nd level ul, however, if I make overflow:visible then the transition effect with max-height doesn't work properly. I have tried making overflow-y:hidden with overflow-x:visible and that does allow the transition to still work but adds a horizontal scroll bar that you need to scroll to the right to see the 3rd level menu. If you can solve this, i have another question with a bounty on it that I have only gotten 1 poor answer on: BOUNTY QUESTION

My jsFiddle and the relevant code below:

#menu li >  ul {
    position:absolute;
    top:auto;
    left:0;
    width:180px;
    max-height:0;
    box-shadow:1px 2px 10px rgba(100, 100, 100, 0.3);
    visibility: hidden;
    z-index:99999;
    overflow:hidden;
    -webkit-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
     -moz-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
     -o-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
     -ms-transition: max-height 0.2s ease, visibility 0s linear 0.5s;
     transition: max-height 0.2s ease, visibility 0s linear 0.5s;
  background: inherit !important;
}
#menu ul li:hover > ul {
    visibility: visible;
    max-height: 216px;
    transition-delay: 0s;
}
#menu li > ul > li > ul {
  position:absolute;
  top:0 !important;
  left:180px !important;
  width:180px;
  overflow:hidden;
  box-shadow:1px 2px 10px rgba(100, 100, 100, 0.3);
  visibility:hidden;
}

html:

<nav id="menu">
    <ul id="main-nav">
        <li id="port"><a href="portfolio.html">Portfolio</a>
            <ul>
                <li id="regular"><a href="#">Regular</a>
                    <ul>
                        <li id="4col"><a href="#">4 columns</a>
                        </li>                        
                    </ul>
                </li>                
            </ul>
        </li>
        <li id="about" class="parent menu-item"><a href="">About</a>            
        </li>
    </ul>
</nav>

回答1:

Add overflow:visible when hovering over the ul element. In doing so, the transition will still take place because the overflow is hidden prior to hovering over the element.

Updated Example

#menu ul li > ul:hover {
    overflow:visible;
}