gpt4 book ai didi

javascript - 纯 CSS 导航栏 :Hover on List not staying

转载 作者:行者123 更新时间:2023-11-28 06:32:46 24 4
gpt4 key购买 nike

我确定这是纯 css 导航栏的常见问题。我有一个用 ul 和 li 创建的导航栏,但是当我悬停时我无法让菜单停留。我知道问题是只有当我将鼠标悬停在链接上时菜单才会打开,但我不确定如何让它工作。我尝试了 jQuery 鼠标悬停,但它对我不起作用:

@font-face{
font-family: Bebas;
src:url(BEBAS.TTF);
}
body{

margin:0 auto;
height:500px;
font-family: Bebas;

}
.header{
top:0;
position:absolute;
left:0;
right:0;
background:#ff6200;
height:50px;
width:100%;
color:white;
font-family: Bebas;

}
.header .call{

line-height:50px;
}
.call{
width:60%;
margin:0 auto;
}
.login{
float:right;
}
.callme, .loginme{
color:#AF2626;
}
.signup{
margin-left:10px;
}
.number{
margin-left:10px;
}
.navbar{
margin-top:50px;
right:0;
left:0;
position:relative;
height:130px;
width:100%;
background:#F7F7F7;
border-radius:0px;
padding:0px;
}
.inside-navbar{
line-height:130px;
width:60%;
margin:0 auto;
font-size:40px;

}
.logo{
color:#FF6200;
}

#navsman{
font-size:16px;
float:right;
display:inline-block;
min-width:300px;
position:absolute;
padding-right: 20%;
}


#navsman li{
display:inline;
position:relative;
padding-left:15px;
line-height:1.4;
}
#navsman li ul{
position:absolute;
display:none;
}

#navsman li:hover > ul.firstmenu{
display:block !important;
margin-top: -50px;
}

#navsman li ul li{
position:relative;
padding-left:15px;
}
#navsman ul.secondmenu{
margin-left: 40px;
padding-top:15px;
padding-top: 30px;
z-index: 2;
width: 120px;
display:none;
}
#navsman > li:hover > ul {
left: auto;
padding-top: 5px ;
min-width: 100%;
}
#navsman ul.firstmenu li:hover ul.secondmenu{
display:block !important;
margin-top: -50px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/js/bootstrap.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.css" rel="stylesheet"/>
<div class="headwrapper">
<div class="header">
<div class="call"><span class="callme">CALL US NOW!</span> <span class="number">777.77.7777.777</span>
<span class="login"><span class="loginme">LOGIN </span><span class="signup">SIGNUP</span></span>
</div>


</div>
<div class="navbar">
<div class="inside-navbar">
<span>YOUR<span class="logo">LOGO</span></span>

<ul id="navsman">
<li><a href="">Title1</a></li>
<li class="title2"><a href="">Title2</a>
<ul class="firstmenu">
<li><a href="#">SUBMENU1</a></li>
<li><a href="#">SUBMENU2</a></li>
<li><a href="#">SUBMENU3</a>
<ul class="secondmenu">
<li class="secondli-first"><a href="#">Sub link 1</a></li>
<li class="secondli-second"><a href="#">Sub link 1</a></li>
</ul>
</li>
</ul>




<li><a href="">Title3</a></li>
<li><a href="">Title4</a></li>
<li><a href="">Title5</a></li>
<li><a href="">Title6</a></li>
<li><a href="">Title7</a></li>
</div>
</ul>
</div>
</div><!--Navbar end-->
</div>

最佳答案

替换:

#navsman > li:hover > ul {
left: auto;
padding-top: 5px ;
min-width: 100%;
}

与:

#navsman > li:hover > ul li {
left: auto;
padding-top: 5px ;
min-width: 100%;
height: 10px;
margin-top:-15px;
padding-left: 10px;
}

关于javascript - 纯 CSS 导航栏 :Hover on List not staying,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34889984/

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