我需要将下拉菜单设置为此页面,没有内容,占据页面的所有宽度。我还需要将菜单的所有“lorem”链接放在导航栏中的中央。我无法编辑引导类,所以我无法做到这一点。我该如何解决这个问题? (请全页打开,我不知道为什么代码被剪断后悬停菜单不起作用)
.navbar-nav {
display: flex;
justify-content: space-between;
align-items: center;
}
.navbar a:hover {
text-decoration: underline;
}
.navbar-nav {
display: flex;
align-items: center;
justify-content: space-between;
}
.dropdown-menu {
font-size: 0.8rem;
left: 0;
border: none;
text-align: center;
position: absolute;
border-radius: 0;
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.1);
display: grid;
grid-template-columns: auto auto auto auto auto;
visibility: hidden;
min-width: 100%;
z-index: 999;
}
.dropdown:hover .dropdown-menu {
visibility: visible;
}
.dropdown-menu.show {
display: flex;
}
.dropdown-menu a:hover {
color: darkgrey;
text-decoration: none;
}
.dropdown-menu li:first-child a {
color: darkgrey;
padding: 20px 0;
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" role="button" data-bs-toggle="dropdown" aria-expanded="false">Lorem</a>
<div class="dropdown-menu">
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" role="button" data-bs-toggle="dropdown" aria-expanded="false">Lorem</a>
<div class="dropdown-menu">
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" role="button" data-bs-toggle="dropdown" aria-expanded="false">Lorem</a>
<div class="dropdown-menu">
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" role="button" data-bs-toggle="dropdown" aria-expanded="false">Lorem</a>
<div class="dropdown-menu">
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" role="button" data-bs-toggle="dropdown" aria-expanded="false">Lorem</a>
<div class="dropdown-menu">
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="" role="button" data-bs-toggle="dropdown" aria-expanded="false">Lorem</a>
<div class="dropdown-menu">
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
<ul>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
<li><a class="dropdown-item" href="">Lorem Ipsum</a></li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</nav>
js代码添加srcipt标签了吗?
要使用 bootstap,您需要 popperjs 和 bootstrap js 代码。
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>
参考: https://getbootstrap.com/docs/5.3/getting-started/download/#cdn-via-jsdelivr