,可以通过以下步骤实现:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Logo</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown Menu
</a>
<ul class="dropdown-menu" style="height: 200px; overflow-y: auto;" aria-labelledby="navbarDropdownMenuLink">
<!-- 可滚动的内容 -->
<li><a class="dropdown-item" href="#">Item 1</a></li>
<li><a class="dropdown-item" href="#">Item 2</a></li>
<li><a class="dropdown-item" href="#">Item 3</a></li>
<li><a class="dropdown-item" href="#">Item 4</a></li>
<li><a class="dropdown-item" href="#">Item 5</a></li>
<li><a class="dropdown-item" href="#">Item 6</a></li>
<li><a class="dropdown-item" href="#">Item 7</a></li>
<li><a class="dropdown-item" href="#">Item 8</a></li>
<li><a class="dropdown-item" href="#">Item 9</a></li>
<li><a class="dropdown-item" href="#">Item 10</a></li>
<!-- 可滚动的内容结束 -->
</ul>
</li>
</ul>
</div>
</div>
</nav>
<ul>
元素添加了样式style="height: 200px; overflow-y: auto;"
,其中height
属性设置了固定的高度,overflow-y
属性设置了垂直方向上的滚动条。这样,当下拉菜单中的内容超过指定的高度时,会出现垂直滚动条,用户可以通过滚动条来查看超出显示范围的菜单项。
推荐的腾讯云相关产品:腾讯云服务器(CVM)和腾讯云负载均衡(CLB)。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云