gpt4 book ai didi

javascript - 悬停 Bootstrap Navbar 间隙问题

转载 作者:行者123 更新时间:2023-11-30 19:46:05 25 4
gpt4 key购买 nike

我想要一个悬停的导航栏,效果很好,但我想保持网站的风格。该站点的下拉菜单位于导航栏下方 20 像素处,当您将鼠标悬停在导航栏上并转到它隐藏的下拉菜单时。它看起来类似于:

继承人和例子on codepen.io

.dropdown:hover>.dropdown-menu {
display: block;
}

.dropdown>.dropdown-toggle:active {
/*Without this, clicking will make it sticky*/
pointer-events: none;
}

.dropdown-menu{
margin-top:20px;
}

最佳答案

您可以使用内部 <div> 尝试以下解决方案元素将菜单项向下推。我还建议为您的自定义使用一个额外的类(在本例中为 .custom-dropdown ),以便您只更改自定义下拉列表而不是您这边的所有下拉元素。

html, body {
background: #ccc;
}
.custom-dropdown.dropdown:hover > .dropdown-menu {
display: block;
margin: 0;
background: transparent;
}

.custom-dropdown.dropdown > .dropdown-toggle:active {
/** without this, clicking will make it sticky. */
pointer-events: none;
}

.custom-dropdown .dropdown-menu .inner-dropdown-menu {
margin-top: 20px;
padding: .5rem 0;
background: white;
}
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="dropdown custom-dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown button</button>
<div class="dropdown-menu border-0" aria-labelledby="dropdownMenuButton">
<div class="inner-dropdown-menu border rounded">
<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>
</div>
</div>
</div>
</body>
</html>

关于javascript - 悬停 Bootstrap Navbar 间隙问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54924996/

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