将鼠标悬停在远离父项时子菜单消失 (css)
Submenu disappearing when hover away from parent (css)
目前,当我将鼠标悬停在父菜单上时,我网站上的子菜单会消失(请参阅 www.fitnessdelicious.com 处的导航菜单)。我已经尝试了其他线程中的几种既定解决方案,但到目前为止似乎没有任何效果。我对我正在做的 html- 和 CSS- 有一些想法,但现在老实说我不知道如何继续。请帮忙? 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>
我不会为您解答,而是会指出您以后可以在哪里找到您的答案。在 mac 上 Chrome(Command Shift I)打开开发人员面板,然后右键单击您感到困惑的菜单栏和 select "Inspect Element".
您会看到页面上的元素,对于每个 selected 元素,您会在样式选项卡中看到应用到它的样式。
举个例子:
快速浏览一下你的,我看到一种颜色被应用于白色的导航图标 class。当我单击以禁用它时,我看到其余文本显示为黑色。所以它就在那里,现在您需要找到设置红色的位置。查看元素列表和样式选项卡,您会找到它。
试试这个 js fiddle 代码:
http://jsfiddle.net/mf3y6Lj6/2/
Its examples, you can follow this structure for the same
/* 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;
}
<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>
我添加了 css class ...有效。
#mainnav-menu a:link, #mainnav-menu a:visited{
display:inline-block !important;
}
您还可以使用 before 或 after 伪元素来创建一些透明填充。这样你就可以延长项目的长度。
目前,当我将鼠标悬停在父菜单上时,我网站上的子菜单会消失(请参阅 www.fitnessdelicious.com 处的导航菜单)。我已经尝试了其他线程中的几种既定解决方案,但到目前为止似乎没有任何效果。我对我正在做的 html- 和 CSS- 有一些想法,但现在老实说我不知道如何继续。请帮忙? 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>
我不会为您解答,而是会指出您以后可以在哪里找到您的答案。在 mac 上 Chrome(Command Shift I)打开开发人员面板,然后右键单击您感到困惑的菜单栏和 select "Inspect Element".
您会看到页面上的元素,对于每个 selected 元素,您会在样式选项卡中看到应用到它的样式。
举个例子: 快速浏览一下你的,我看到一种颜色被应用于白色的导航图标 class。当我单击以禁用它时,我看到其余文本显示为黑色。所以它就在那里,现在您需要找到设置红色的位置。查看元素列表和样式选项卡,您会找到它。
试试这个 js fiddle 代码: http://jsfiddle.net/mf3y6Lj6/2/
Its examples, you can follow this structure for the same
/* 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;
}
<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>
我添加了 css class ...有效。
#mainnav-menu a:link, #mainnav-menu a:visited{
display:inline-block !important;
}
您还可以使用 before 或 after 伪元素来创建一些透明填充。这样你就可以延长项目的长度。