gpt4 book ai didi

html - Bootstrap 4 下拉触发错误的元素

转载 作者:行者123 更新时间:2023-11-28 15:07:48 24 4
gpt4 key购买 nike

我正在开发一个导航栏,其中有 2 个元素有下拉菜单。第一个下拉列表工作正常,但第二个总是触发第一个。我在删除我添加的所有额外样式后对其进行了测试,但它仍然无法正常工作。

我确定这是显而易见的事情,但我似乎无法弄明白。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href="css/app.css" rel="stylesheet" />

<!-- NAVIGATION BAR -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarCollapsing" aria-controls="navbarCollapsing" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<h1 class="navbar-brand mb-0">
<img class="pigs-logo" src="assets/logo.png">
</h1>
<div class="collapse navbar-collapse" id="navbarCollapsing">
<div class="nav navbar-nav">
<a class="nav-item nav-link active" href="./index.html">
Home
</a>
<a class="nav-item nav-link" href="./tour.html">
Tour
</a>
<a class="nav-item nav-link dropdown-toggle" href="#" id="navbar-media" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Media
</a>
<div class="dropdown">
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbar-media">
<a class="dropdown-item" href="./videos.html">
Videos
</a>
<a class="dropdown-item" href="./photos.html">
Photos
</a>
<a class="dropdown-item" href="./audio.html">
Audio
</a>
</div>
</div>
<a class="nav-item nav-link" href="./about.html">
About
</a>
<a class="nav-item nav-link dropdown-toggle" href="#" id="navbar-contact" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Contact
</a>
<div class="dropdown">
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbar-contact">
<a class="dropdown-item" href="./contact.html">
Contact
</a>
<a class="dropdown-item" href="./booking.html">
Booking
</a>
</div>
</div>
</div>
</div>
</div>
</nav>

最佳答案

在我的例子中,问题是我没有将整个下拉列表(包括触发元素和菜单项)包装在 <div class="dropdown"> 中。 .它仍然有效,直到我添加了第二个下拉菜单并发现它是由错误的元素触发的。

Bootstrap 4 下拉菜单应具有以下基本结构:

<div class="dropdown">
<a href="#" data-toggle="dropdown">Triggering Element</a>
<div class="dropdown-menu">
<a href="#" class="dropdown-item">Item One</a>
<a href="#" class="dropdown-item">Item Two</a>
<a href="#" class="dropdown-item">Item Three</a>
</div>

</div>

我缺少外层 <div> .

关于html - Bootstrap 4 下拉触发错误的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49081060/

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