简体   繁体   English

隐藏在导航栏中的下拉菜单

[英]Dropdown menu hidden within navbar

i'm doing a project in which I have to make a website from scratch using no frameworks. 我正在做一个项目,在这个项目中,我必须不使用任何框架从头开始制作网站。 The problem i'm having is that I'd like to make a navigation bar that can collapse down on mobile devices aswell as have a dropdown menu on a desktop. 我遇到的问题是我想制作一个导航栏,该导航栏可以在移动设备上折叠,也可以在桌面上使用下拉菜单。

I've managed to get it properly working for mobile devices, but when on a desktop the dropdown menus just hide within the nav bar container. 我设法使它在移动设备上正常工作,但是在桌面上时,下拉菜单仅隐藏在导航栏容器中。 I believe this is a problem where the height isn't adjusting for the dropdown, but i'm not too sure how i'd fix it. 我认为这是一个高度无法根据下拉菜单进行调整的问题,但我不太确定如何解决。 The navigation bar has to be fixed to the top, collapse when below 900px and the dropdowns must be visible when hovering over them. 导航栏必须固定在顶部,低于900px时折叠,并且将鼠标悬停在下拉菜单上必须可见。

The Website in question is http://www.ico.mmu.ac.uk/13143651/webdev/ 有问题的网站为http://www.ico.mmu.ac.uk/13143651/webdev/

CSS 的CSS

nav {
background-color: #b8b8b8;
font-family: arial;
position: fixed;
top: 0;
z-index:999;
text-decoration: none;
width: 100%;
padding:0px;
overflow:auto;
margin:0px;
clear:both;
}

HTML 的HTML

<nav role="navigation">
<ul class="slimmenu" id="navigation">
<li>
    <a href="pages/courses.html">Courses</a>
    <ul>
        <li><a href="pages/media.html">Digital Media</a></li>
        <li><a href="pages/webdev.html">Web Development</a></li>
        <li><a href="pages/journalism.html">Journalism</a></li>
        <li><a href="pages/infocomms.html">Information Communications</a></li>
    </ul>
</li>
<li>
    <a href="pages/facilities.html">Facilities</a>
    <ul>
        <li><a href="pages/society.html">Societies</a></li>
        <li><a href="pages/jobs.html">Jobs and Placements</a></li>
        <li><a href="pages/library.html">Library</a></li>
    </ul>
</li>
<li>
    <a href="pages/manchester.html">Manchester and Student Life</a>
    <ul>
        <li><a href="pages/travel.html">Travel</a></li>
        <li><a href="pages/attactions.html">Attractions</a></li>
        <li><a href="pages/night.html">Nightlife</a></li>
    </ul>
</li>
<li>
    <a href="pages/help.html">Student Help</a>
    <ul>
        <li><a href="pages/finance.html">Finance</a></li>
        <li><a href="pages/union.html">Student Union</a></li>
        <li><a href="pages/assist.html">Assistance</a></li>
    </ul>
</li>

<li><a href="pages/contact.html">Contact</a></li>
</nav>

Thanks in advance. 提前致谢。

It's hard to know what the desired behaviour is, but you can try variations on this: 很难知道所需的行为是什么,但是您可以尝试以下变化:

ul.slimmenu li > ul{
    position: fixed; 
    top: 50px;
    left: none;
}

In your css, change your .nav overflow rule. 在您的CSS中,更改.nav溢出规则。

From

overflow: auto

to

overflow: visible

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

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