悬停菜单消失得太快
Hover menu disappear too fast
我遇到了问题,我不知道悬停菜单有什么问题,但它消失得太快了
<div class="dropdown">
<li class="nav-item log-main">
<a href="#" class="nav-link" data-toggle="dropdown">Member</a>
<ul class=" dropdown-menu log">
<li><a href="sign_in.html" class="dropdown-item">Sign up</a></li>
<li><a href="log_in.html" class="dropdown-item">Log in</a></li>
</ul>
</li>
</div>
css:
.navbar .nav-item ul.log{
display: none;
list-style-type:none;
}
.navbar .dropdown-menu:hover ul.log{
display: block;
}
.log a{
color:var(--main-text-color);
font-family:var(--main-text-font);
font-size: 24px;
}
您需要将悬停添加到可见的元素和隐藏的下拉列表。
.dropdown:hover .dropdown-menu,
.dropdown .dropdown-menu:hover{
display: block;
position: absolute;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</nav>
您需要在 .log-main:hover
上使用 :hover
伪 class 来显示下一个 ul
,即 .dropdown-menu
现场演示:
.navbar .nav-item ul.log {
display: none;
list-style-type: none;
}
.log-main:hover .dropdown-menu {
display: block;
margin-top: 0;
}
.log a {
color: var(--main-text-color);
font-family: var(--main-text-font);
font-size: 24px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="dropdown">
<li class="nav-item log-main">
<a href="#" class="nav-link" data-toggle="dropdown">Member</a>
<ul class="dropdown-menu log">
<li><a href="sign_in.html" class="dropdown-item">Sign up</a></li>
<li><a href="log_in.html" class="dropdown-item">Log in</a></li>
</ul>
</li>
</div>
我遇到了问题,我不知道悬停菜单有什么问题,但它消失得太快了
<div class="dropdown">
<li class="nav-item log-main">
<a href="#" class="nav-link" data-toggle="dropdown">Member</a>
<ul class=" dropdown-menu log">
<li><a href="sign_in.html" class="dropdown-item">Sign up</a></li>
<li><a href="log_in.html" class="dropdown-item">Log in</a></li>
</ul>
</li>
</div>
css:
.navbar .nav-item ul.log{
display: none;
list-style-type:none;
}
.navbar .dropdown-menu:hover ul.log{
display: block;
}
.log a{
color:var(--main-text-color);
font-family:var(--main-text-font);
font-size: 24px;
}
您需要将悬停添加到可见的元素和隐藏的下拉列表。
.dropdown:hover .dropdown-menu,
.dropdown .dropdown-menu:hover{
display: block;
position: absolute;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</nav>
您需要在 .log-main:hover
上使用 :hover
伪 class 来显示下一个 ul
,即 .dropdown-menu
现场演示:
.navbar .nav-item ul.log {
display: none;
list-style-type: none;
}
.log-main:hover .dropdown-menu {
display: block;
margin-top: 0;
}
.log a {
color: var(--main-text-color);
font-family: var(--main-text-font);
font-size: 24px;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div class="dropdown">
<li class="nav-item log-main">
<a href="#" class="nav-link" data-toggle="dropdown">Member</a>
<ul class="dropdown-menu log">
<li><a href="sign_in.html" class="dropdown-item">Sign up</a></li>
<li><a href="log_in.html" class="dropdown-item">Log in</a></li>
</ul>
</li>
</div>