简体   繁体   English

如何在容器外部显示导航栏下拉菜单?

[英]How to show navbar dropdown menu outside container?

So before this problem, I was struggling to make the navbar scroll on smaller screens when expanded. 因此,在出现此问题之前,我一直在努力使导航栏在展开时在较小的屏幕上滚动。 SO link: responsive fixed-top navbar when expanded fills up screen, hides some of the nav-links, and does not scroll SO链接: 扩展后的自适应顶部导航栏会填满屏幕,隐藏某些导航链接,并且不会滚动

Using the answer in that question, I was able to make the navbar scroll but I was then faced with a new issue. 使用该问题的答案,我可以使导航栏滚动,但是随后我遇到了一个新问题。 When clicked on the navbar link, the dropdown menu that popped up would stay within the navbar container, and the navbar could be scrolled. 当单击导航栏链接时,弹出的下拉菜单将保留在导航栏容器中,并且可以滚动导航栏。

A picture to explain (OLE dropdown in this case) : 图片说明(在此情况下为OLE下拉列表) 在此处输入图片说明

This is the CSS used to make the collapsed navbar scrollable. 这是用于使折叠的导航栏可滚动的CSS。

.fixed-top .navbar-collapse {
    max-height: calc(100vh - 4.5em);
    overflow-y: auto;
}

There is no problem when navbar collapsed and it can show the dropdown menu fine and scroll. 导航栏折叠时没有问题,它可以正常显示下拉菜单并滚动。 But, when not collapsed on larger screen, how do i make the dropdown menu show outside the navbar container? 但是,当未在大屏幕上折叠时,如何使下拉菜单显示在导航栏容器之外?

Here's my JSFiddle for this problem: https://jsfiddle.net/suhaib47/7b58o0d3/3/ 这是我针对这个问题的JSFiddle: https ://jsfiddle.net/suhaib47/7b58o0d3/3/
Note: make the result viewport wide enough that navbar can be fully displayed. 注意:使结果视口足够宽,以使导航栏可以完全显示。 Click on the OLE dropdown, and you will have to scroll down to see the dropdown menu. 单击OLE下拉菜单,然后您必须向下滚动才能看到下拉菜单。


When I show the dropdown menu outside the container, the menu cannot be scrolled on smaller screens. 当我在容器外部显示下拉菜单时,无法在较小的屏幕上滚动菜单。 When the menu CAN be scrolled, I cannot get the dropdown menu to show outside the nav container. 当菜单可以滚动时,我无法获得下拉菜单显示在导航容器外部。

How do I make the dropdown menu show outside the navbar container? 如何使下拉菜单显示在导航栏容器之外? At the same time I'd like the responsive navbar to be scrollable when expanded on smaller screens. 同时,我希望在较小的屏幕上展开时,响应式导航栏可滚动。

I found a similar SO question but could not get it to fix my problem: The navbar dropdown menu does not beyond the container 我发现了类似的问题,但无法解决此问题: 导航栏下拉菜单没有超出容器范围

Hoped there would be a solution to this without having to use media queries. 希望有一种解决方案,而不必使用媒体查询。 Nevertheless, I was indeed able to fix this using media query. 不过,我确实能够使用媒体查询解决此问题。

@media only screen and (max-height: 450px) {
    .fixed-top .navbar-collapse {
        max-height: calc(100vh - 4.5em);
        overflow-y: auto;
    }
}

This way scrolling is available when needed, depending on the display size/orientation, ie when the navbar menu is collapsed. 视显示大小/方向而定,即在折叠导航栏菜单时,可以在需要时使用这种滚动方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM