gpt4 book ai didi

html - 悬停时隐藏子菜单

转载 作者:太空宇宙 更新时间:2023-11-03 21:37:23 27 4
gpt4 key购买 nike

我有 HTML 菜单和子菜单。出于某种原因,当我将鼠标悬停在子菜单上时,子菜单会隐藏。当我将鼠标悬停在父菜单上时,子菜单会显示,一旦悬停在子菜单上它就会隐藏。

HTML

<div id="main-menu">
<ul>
<li><a href="#" class="sf-with-ul">Home<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">Start here</span></a></li>
<li><a href="#" class="sf-with-ul">Features<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">remix all features</span></a>
<ul class="transparency">
<li><a href="#">Accordion</a></li>
<li><a href="#">Buttons</a></li>
<li><a href="#" class="sf-with-ul">Typography</a></li>
</ul>
</li>
<li><a href="#">MP3<span class="sub">full archive</span></a></li>
<li><a href="#">Video<span class="sub">latest clips</span></a></li>
<li><a href="#" class="sf-with-ul">Gallery<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">Photo Gallery</span></a>
<ul class="transparency">
<li><a href="#">Gallery 4 Column</a></li>
<li><a href="#">Gallery 3 Column</a></li>
<li><a href="#">Gallery 2 Column</a></li>
</ul>
</li>
<li><a href="#">Pages<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">more templates</span></a>
<ul class="transparency">
<li><a href="#">RTL Support</a></li>
<li><a href="#">Events</a></li>
<li><a href="#">MP3 Single Wide</a></li>
</ul>
</li>
<li><a href="#">Blog<span class="sf-sub-indicator"><i class="icon-angle-down"></i></span><span class="sub">latest news</span></a>
<ul class="transparency">
<li><a href="#">Blog</a></li>
<li><a href="#">Blog Left Sidebar</a></li>
<li><a href="#">Blog Both Sidebar</a></li>
</ul>
</li>
</ul>
</div>

CSS

#main-menu{
float: right;
position: relative;
margin: 20px 0 0 -20px;
}
#main-menu ul{
float: right;
padding: 0;
position: relative;
margin: 0;
list-style: none;
}
#main-menu li{
float: left;
position: relative;
padding: 0;
}
#main-menu a{
padding:0 20px 22px 0;
display: block;
position: relative;
color: #fff;
text-transform: uppercase;
font-size: 14px;
text-decoration: none;
font-weight: bold;
}
#main-menu li a span {
font-size: 12px;
font-family: tahoma;
font-weight: normal;
text-transform: none;
display: block;
color: #AFAFAF;
margin: 10px 0 0 0;
}
#main-menu li ul{
display: none;
position: absolute;
width: 170px;
word-break: break-all;
}
#main-menu li:hover > ul{
display: block;
margin-top: 11px;
}
#main-menu li > ul li{
display: block;
width: 100%;
}
#main-menu li > ul li a:hover{
display: block;
width: 100%;
background: #FFF;
color: #000;
}
#main-menu li > ul li a{
font-weight: normal;
padding: 8px 15px;
line-height: 20px;
color: #fff;
text-transform: none;
letter-spacing: 0;
-webkit-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}

最佳答案

Live demo

只需将此 CSS 中的 margin-top 替换为 padding-top:

#main-menu li:hover > ul {
display: block;
margin-top: 11px;
}

这样就变成了:

#main-menu li:hover > ul {
display: block;
padding-top: 11px;
}

证明:

enter image description here

关于html - 悬停时隐藏子菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25707709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com