gpt4 book ai didi

html - 导航栏下拉菜单不起作用 Bootstrap 下拉 anchor 在单击时不起作用

转载 作者:行者123 更新时间:2023-12-04 17:12:15 27 4
gpt4 key购买 nike

我正在尝试使用 Bootstrap 构建一个带有下拉菜单的导航栏。
但是当我点击内容按钮时,下拉菜单不起作用。我想我已经在代码中的正确位置包含了引导 CDN 链接、引导 css 链接、css 链接和 jquery 链接。
我加了一点 CSS
我现在会放一个视频链接,但稍后我会添加另一个页面。我想要一个点击下拉操作
这是一个片段

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>topMenu</title>
<link rel="stylesheet" type="text/css" href="../resources/css/topMenu.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css"/>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<li class="logo"><a href="${path}/#home"><img src="../resources/css/frontLogo.png" ></a></li>
</div>

<div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">

<li class="item"><a href="${path }/#home"><b>Home</b></a></li>
<li class="item"><a href="${path }/#about">About</a></li>
<li class="item"><a href="${path}/news/newsList">News</a></li>


<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Contents
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="https://www.youtube.com/channel/UCMpp2Ln-XtD36-iUL3Yd1rw" target="_blank">Videos</a></li>
</ul>
</li>





</ul>
</div>
</div>
</div>
</nav>

</body>
</html>

CSS在这里:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

body {
font-family: sans-serif;
background: rgb(13,13,13);
}


.navbar {
background: rgb(27, 27, 27);
}
.nav li > a {
color: white !important;
}

a:hover {
text-decoration: underline;

}
.logo img{
margin-top:5px;
margin-left:-5px;
display:block;
width:50px;

}

#myNavbar {
font-size: 15px;
}

最佳答案

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>topMenu</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>

</head>
<body>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="${path}/#home"><img src="../resources/css/frontLogo.png" ></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarScroll" aria-controls="navbarScroll" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarScroll">
<ul class="navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll" style="--bs-scroll-height: 100px;">
<li class="nav-item"><a class="nav-link" href="${path }/#home"><b>Home</b></a></li>
<li class="nav-item"><a class="nav-link" href="${path }/#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="${path}/news/newsList">News</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Link
</a>
<ul class="dropdown-menu" aria-labelledby="navbarScrollingDropdown">
<li><a class="dropdown-item" href="https://www.youtube.com/channel/UCMpp2Ln-XtD36-iUL3Yd1rw" target="_blank">Videos</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>

</body>
</html>

关于html - 导航栏下拉菜单不起作用 Bootstrap 下拉 anchor 在单击时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69220164/

27 4 0