下拉菜单不起作用

时间:2015-07-02 10:40:47

标签: html css wordpress drop-down-menu

我用一个简单的CSS下拉菜单制作了一个wordpress模板。我使用的代码是我经常使用的代码,但是这次当您将鼠标悬停在按钮上而不想悬停在显示的下拉菜单上时,下拉菜单将会消失。

有人知道如何解决这个问题以及出了什么问题?

链接到模板:http://bit.ly/1Ivcg2U

#navigation ul {
	list-style: none;
	width: 800px;
	height: 40px;
	padding: 0;
	margin: 0 auto;
}

#navigation li {
	float: left;
	position: relative;
	z-index: 500;
	display: block;
	text-align: center;
	margin: 0px 40px;
	padding: 5px;
}

#navigation li ul {
    display: none;
    position: absolute;
  	max-width: 140px;
  	top: 40px;
	left: -20px;
}

ul#categories li {
	width: 100%;
 	float: left;
 	margin: 0;
 	background: #fff;
}

ul#categories a {
	padding: 10px;
	width: 200px;
}

ul#categories li:hover{
 	background: #000;
}

ul#navigation li:hover > ul,
#navigation ul li:hover > ul {
        display: block; /* display the dropdown */
}


#navigation a {
	font-family: 'Montserrat';
	color: #474747;
	text-decoration: none;
	font-weight: 300;
	letter-spacing: 2px;
	text-transform: uppercase;
	font-size: 10px;
}

li a:hover {
	color: #000;
	font-family: 'Montserrat';
}

ul#categories li a:hover {
	color: #fff;
}
<div id="bar">
<div id="navigation">
  <ul id="nav">
    <li><a href="http://todaysbeauty.nl">Home</a></li>
    <li>
      <a href="#">Categorieën</a>
      <ul id="categories">
        <li><a href="/category/travel/">travel</a></li>
        <li><a href="/category/beauty/">Beauty</a></li>
        <li><a href="/category/fashion/">Fashion</a></li>
        <li><a href="/category/lifestyle/">Lifestyle</a></li>
        <li><a href="/category/persoonlijk/">Persoonlijk</a></li>
        <div class="clear"></div>
      </ul>
    </li>
    <li>
      <a href="/over-mij" class="selected">Over mij</a>
      <div class="clear"></div>
    </li>
    <li>
      <a href="/contact">Contact</a>	
      <div class="clear"></div>
    </li>
    <li>
      <a href="/zakelijk" class="selected">Zakelijk</a>
      <div class="clear"></div>
    </li>
  </ul>
</div>

1 个答案:

答案 0 :(得分:1)

问题是您的二级菜单距离您的顶级太低:

#navigation li ul {
    display: none;
    position: absolute;
    max-width: 140px;
    top: 40px;/* Change this to a lower value so it overlaps or doesn't leave a gap with menu above*/
    left: -20px;
}

当光标移动到间隙时,它不再处于&#39;悬停&#39;状态,所以下拉消失。缩小差距将解决问题。