远离父母(css)时子菜单消失

时间:2015-02-03 06:07:45

标签: css navigation submenu

目前,当我将鼠标悬停在父母身上时,我网站上的子菜单会消失(请参阅www.fitnessdelicious.com上的导航菜单)。我已尝试过其他线程的几个解决方案,但到目前为止似乎没有任何工作。我知道我正在做什么html-和CSS-wise,但现在老老实实地不知道如何继续。请帮忙?下面的CSS片段。谢谢!

/* Navigation Menu
-------------------------------------------------------------- */
#mainnav-icon {
	display: none;
}
#navi-wrap {
	background: #fff;
}
#mainnav-menu {
	list-style-type: none;
	list-style-position: outside;
	text-align:left;
			border-top: 1px solid #eceece;
			border-bottom: 1px solid #e6e9bf;
			z-index:100;
			position:relative;
}
#mainnav-menu li{
	float:center;
	position:relative;
	margin-right: 1px;display:inline;
}
#mainnav-menu a {
	display: block;
	padding: .15em;
	font-family: 'Lato', sans-serif; 
	text-transform: uppercase;
	text-decoration: none;
	font-size: 15px;
	font-family: 'Lato', sans-serif;
	-webkit-transition: all 0.1s ease-out;
	-moz-transition: all 0.1s ease-out;
	-ms-transition: all 0.1s ease-out;
	-o-transition: all 0.1s ease-out;
	transition: all 0.1s ease-out;
}
#mainnav-menu a:link, #mainnav-menu a:visited {
	text-decoration: none;
	font-family: 'Lato', sans-serif; 
			font-size:14px;
			font-weight: 300;
			color:#d2da58;
			letter-spacing:2px;
			text-transform:uppercase;
			margin:0 13px;
			height:50px;
			line-height:50px;display:inline;
}
#mainnav-menu a:hover {
	background: #fff;
	color: #ff7a7f;
}

/* Drop-down Menu
-------------------------------------------------------------- */

#mainnav-menu ul {
	position: absolute;
	display: none;
	z-index: 99;
	left: -9999px;
	background: #fff;
	box-shadow: 0 0 2px #444;display:inline;
}
#mainnav-menu ul li{
	margin: 0;
	display: inline;
}
#mainnav-menu ul a {
	width: 250px;
	width: 16rem;
	padding: 1em;

	font-weight: normal;
	color: #333;
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}
#mainnav-menu ul a:link, #mainnav-menu ul a:visited{
	color: #333;
	font-size: 0.9em;
	text-decoration: none;
}
#mainnav-menu ul a:hover {
	color: #fff;
	background: #e84747;
}
#mainnav-menu li ul ul {
	margin-left: 250px;
	margin-left: 16rem;
}
#mainnav-menu li:hover ul ul, #mainnav-menu li:hover ul ul ul, #mainnav-menu li:hover ul ul ul ul{
	display:none; left: 0;
}
#mainnav-menu li:hover ul, #mainnav-menu li li:hover ul, #mainnav-menu li li li:hover ul, #mainnav-menu li li li li:hover ul{
	display: block; left: 0;
}
#mainnav-menu li.current_page_item a, #mainnav-menu li.current-menu-item a {
	text-decoration: none; color: #ff7a7f;
}
#mainnav-menu li.current_page_item ul li a, #mainnav-menu li.current-menu-item ul li a{
	text-decoration: none; color: #ff7a7f;
}
#mainnav-menu ul li.current_page_item a, #mainnav-menu ul li.current-menu-item a {
	text-decoration: none; color: #ff7a7f;
}
#mainnav-menu ul li.current_page_item ul li a, #mainnav-menu ul li.current-menu-item ul li a{
	text-decoration: none; color: #ff7a7f;
}
	<div id="navi-wrap">
		<nav id="mainnav" class="container clearfix" role="navigation">
			<h4 id="mainnav-icon">Menu</h4>
			<ul id="mainnav-menu" class="menu"><li id="menu-item-25" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-24 current_page_item menu-item-25"><a href="http://www.fitnessdelicious.com/">Home</a></li>
<li id="menu-item-13" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-13"><a href="http://www.fitnessdelicious.com/recipes/">Recipes</a></li>
<li id="menu-item-41" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-41"><a href="http://www.fitnessdelicious.com/diet/">Diet deliciously</a>
<ul class="sub-menu">
	<li id="menu-item-86" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-86"><a href="http://www.fitnessdelicious.com/the-method/">The Method</a></li>
	<li id="menu-item-90" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-90"><a href="http://www.fitnessdelicious.com/the-tools/">The Tools</a></li>
</ul>
</li>
<li id="menu-item-16" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-16"><a href="http://www.fitnessdelicious.com/sample-page/">Boutique</a></li>
<li id="menu-item-54" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-54"><a href="http://www.fitnessdelicious.com/active-living/">Active Living</a></li>
<li id="menu-item-44" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-44"><a href="http://www.fitnessdelicious.com/aging/">Youthful Aging</a></li>
<li id="menu-item-50" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-50"><a href="http://www.fitnessdelicious.com/about/">About</a></li>
</ul>		</nav>

4 个答案:

答案 0 :(得分:1)

&#13;
&#13;
/* Navigation Menu
-------------------------------------------------------------- */
#mainnav-icon {
	display: none;
}
#navi-wrap {
	background: #fff;
}
#mainnav-menu {
	list-style-type: none;
	list-style-position: outside;
	text-align:left;
			border-top: 1px solid #eceece;
			border-bottom: 1px solid #e6e9bf;
			z-index:100;
			position:relative;
}
#mainnav-menu li{
	float:center;
	position:relative;
	margin-right: 1px;display:inline;
}
#mainnav-menu a {
	display: block;
	padding: .15em;
	font-family: 'Lato', sans-serif; 
	text-transform: uppercase;
	text-decoration: none;
	font-size: 15px;
	font-family: 'Lato', sans-serif;
	-webkit-transition: all 0.1s ease-out;
	-moz-transition: all 0.1s ease-out;
	-ms-transition: all 0.1s ease-out;
	-o-transition: all 0.1s ease-out;
	transition: all 0.1s ease-out;
}
#mainnav-menu a:link, #mainnav-menu a:visited {
	text-decoration: none;
	font-family: 'Lato', sans-serif; 
			font-size:14px;
			font-weight: 300;
			color:#d2da58;
			letter-spacing:2px;
			text-transform:uppercase;
			margin:0 13px;
			height:50px;
			line-height:50px;display:inline-block;
}
#mainnav-menu a:hover {
	background: #fff;
	color: #ff7a7f;
}

/* Drop-down Menu
-------------------------------------------------------------- */

#mainnav-menu ul {
	position: absolute;
	display: none;
	z-index: 99;
	left: -9999px;
	background: #fff;
	box-shadow: 0 0 2px #444;display:inline;
}
#mainnav-menu ul li{
	margin: 0;
	display: inline;
}
#mainnav-menu ul a {
	width: 250px;
	width: 16rem;
	padding: 1em;
    display:inline;
	font-weight: normal;
	color: #333;
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}
#mainnav-menu ul a:link, #mainnav-menu ul a:visited{
	color: #333;
	font-size: 0.9em;
	text-decoration: none;
  display:inline-block;
  
}
#mainnav-menu ul a:hover {
	color: #fff;
	background: #e84747;
}
#mainnav-menu li ul ul {
	margin-left: 250px;
	margin-left: 16rem;
}
#mainnav-menu li:hover ul ul, #mainnav-menu li:hover ul ul ul, #mainnav-menu li:hover ul ul ul ul{
	display:none; left: 0;
}
#mainnav-menu li:hover ul, #mainnav-menu li li:hover ul, #mainnav-menu li li li:hover ul, #mainnav-menu li li li li:hover ul{
	display: block; left: 0;
}
#mainnav-menu li.current_page_item a, #mainnav-menu li.current-menu-item a {
	text-decoration: none; color: #ff7a7f;
}
#mainnav-menu li.current_page_item ul li a, #mainnav-menu li.current-menu-item ul li a{
	text-decoration: none; color: #ff7a7f;
}
#mainnav-menu ul li.current_page_item a, #mainnav-menu ul li.current-menu-item a {
	text-decoration: none; color: #ff7a7f;
}
#mainnav-menu ul li.current_page_item ul li a, #mainnav-menu ul li.current-menu-item ul li a{
	text-decoration: none; color: #ff7a7f;
}
&#13;
<div id="navi-wrap">
		<nav id="mainnav" class="container clearfix" role="navigation">
			<h4 id="mainnav-icon">Menu</h4>
			<ul id="mainnav-menu" class="menu"><li id="menu-item-25" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-24 current_page_item menu-item-25"><a href="http://www.fitnessdelicious.com/">Home</a></li>
<li id="menu-item-13" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-13"><a href="http://www.fitnessdelicious.com/recipes/">Recipes</a></li>
<li id="menu-item-41" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-41"><a href="http://www.fitnessdelicious.com/diet/">Diet deliciously</a>
<ul class="sub-menu">
	<li id="menu-item-86" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-86"><a href="http://www.fitnessdelicious.com/the-method/">The Method</a></li>
	<li id="menu-item-90" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-90"><a href="http://www.fitnessdelicious.com/the-tools/">The Tools</a></li>
</ul>
</li>
<li id="menu-item-16" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-16"><a href="http://www.fitnessdelicious.com/sample-page/">Boutique</a></li>
<li id="menu-item-54" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-54"><a href="http://www.fitnessdelicious.com/active-living/">Active Living</a></li>
<li id="menu-item-44" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-44"><a href="http://www.fitnessdelicious.com/aging/">Youthful Aging</a></li>
<li id="menu-item-50" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-50"><a href="http://www.fitnessdelicious.com/about/">About</a></li>
</ul>		</nav>
&#13;
&#13;
&#13;

我添加了css类......它有效。

#mainnav-menu a:link, #mainnav-menu a:visited{
display:inline-block !important;
}

答案 1 :(得分:0)

我没有为你回答,而是指出你可以在这里找到你的答案。在Mac上打开Chrome(Command Shift I)中的开发人员面板,然后右键单击您感到困惑的菜单栏并选择&#34; Inspect Element&#34;。

您将看到页面上的元素,并且对于每个选定的元素,您将在样式选项卡中看到应用于它的样式。

举个例子: 只需快速浏览一下,我就会看到一种颜色应用于导航图标类白色。当我单击以禁用它时,我看到其余文本显示为黑色。所以它就在那里,现在你需要找到红色的设置位置。查看元素列表和样式选项卡,您就可以找到它。

答案 2 :(得分:0)

试试这个js小提琴代码: http://jsfiddle.net/mf3y6Lj6/2/

Its examples, you can follow this structure for the same

答案 3 :(得分:0)

您还可以使用一个伪元素之前或之后创建一些透明的填充。这样,您可以延长商品的长度。