【发布时间】:2015-02-28 18:02:28
【问题描述】:
我正在使用 CSS 创建一个下拉菜单。但是,当我选择菜单时,它会在列表将出现的空间中以及从 UL 中选择。不只是 UL,如果这有意义的话,我无法弄清楚它为什么这样做。请看示例代码:-
CSS:-
#navigation .menu ul {position:absolute; top:45px; left:0px; opacity:0; background:black; transition:opacity .25s ease; -webkit-transition:opacity .25s ease;}
#navigation .menu li:hover > ul {opacity:1; margin:0;}
#navigation .menu ul li {height:25px; width:200px; overflow:hidden; border-bottom:red 1px solid; border-left:none; margin:none; transition:opacity .25s ease; -webkit-transition:height .25s ease;}
#navigation .menu ul li:hover {overflow:hidden; margin:0;}
#navigation .menu ul li a {text-decoration:none; height:25px; width:200px;}
#navigation .menu ul li:last-child {border-bottom:none;}
HTML 代码:-
<div id="navigation"> <nav> <ul class="menu">
<li> <a href="Option.html"> <h1> Homepage </h1> </a> </li>
<li> <a href="Option2.html"> About </a> <ul class="ulbox">
<li class="dm"> <a href="Option1.html"> <img src="images/Avengers.jpeg" width="25" /> The Site </a></li>
<li class="dm"> <a href="Option2.html"> <img src="images/Doctor Strange.jpeg" width="25" /> Find Us </a></li>
<li class="dm"> <a href="Option3.html"> <img src="images/Guardians.jpeg" width="25" /> The Company </a></li>
<li class="dm"> <a href="Option4.html"> <img src="images/Inhumans.jpeg" width="25" /> Contrived Page </a></li>
<li class="dm"> <a href="Option5.html"> <img src="images/Thor.jpeg" width="25" /> Drop Down Success </a></li>
</ul> </li>
<li> <a href="Option3.html"> Images </a> <ul>
<li> <a href="Option1.html"> The Site </a></li>
<li> <a href="Option2.html"> Find Us </a></li>
<li> <a href="Option3.html"> The Company </a></li>
<li> <a href="Option4.html"> Contrived Page </a></li>
<li> <a href="Option5.html"> Drop Down Success </a></li>
</ul> </li>
<li> <a href="Option4.html"> The next page </a> <ul>
<li> <a href="Option1.html"> The Site </a></li>
<li> <a href="Option2.html"> Find Us </a></li>
<li> <a href="Option3.html"> The Company </a></li>
<li> <a href="Option4.html"> Contrived Page </a></li>
<li> <a href="Option5.html"> Drop Down Success </a></li>
</ul> </li>
<li> <a href="Option5.html"> Terms and Stuff </a> <ul>
<li> <a href="Option1.html"> The Site </a></li>
<li> <a href="Option2.html"> Find Us </a></li>
<li> <a href="Option3.html"> The Company </a></li>
<li> <a href="Option4.html"> Contrived Page </a></li>
<li> <a href="Option5.html"> Drop Down Success </a></li>
</ul> </li> </ul> </nav> </div>
我看不出为什么菜单会从 UL 导航栏外显示。有人可以帮忙吗?
【问题讨论】:
-
你的问题不清楚,请补充一些细节或制作jsfiddle
-
不确定我是否收到您的问题。查看您在
.menu下将position:absolute提供给ul的代码,因此请确保它的父li 具有position:relative -
感谢 anpsmn 的回复。会试一试的。为了解释我的问题,基本上,虽然菜单会下拉,但它会在不悬停在主导航栏上时这样做。当鼠标离我创建的导航栏很远的时候就可以了
标签: css html drop-down-menu nav