问题
I am working on a navbar that was made out of HTML CSS and Bootstrap. I had followed some tutorials on youtube but I can seem to expand the toggle button when the screen size is reduced to the smallest. Since I'm starting a new project, I applied all of this with HTML CSS, and Bootstrap and opened the HTML file in my local directory.
<!doctype html>
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="asset/css/bootstrap.min.css">
<!--<link rel="stylesheet" href="asset/css/bootstrap-rtl.min.css">-->
<link rel="stylesheet" href="asset/css/style.css">
<!--<link rel="stylesheet" href="asset/fontawesome/css/all.min.css">-->
<title>فروشگاه</title>
</head>
<body class="bg-success">
<header>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">خشکبار</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">صفحع اصلی</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">درباره ما</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">فروشگاه</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">اخبار</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">راهنمای خرید</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">تماس با ما</a>
</li>
</ul>
</div>
</nav>
</div>
</header>
<script src="asset/js/jquery-3.5.1.min.js"></script>
<script src="asset/js/bootstrap.bundle.min.js"></script>
<script src="asset/js/popper.min.js"></script>
<script src="asset/js/bootstrap.min.js"></script>
</body>
</html>
回答1:
I created a codeply for you, there is no error in your code, you just need to add a few <script>
s into your code. I recommend you to use the cdn
.
In order to make the hamburger button work, the necessary lines of code are needed:
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
</body>
Make sure you include these lines of code in this specific order.
回答2:
You are using bootstrap and it is required to add some boot strap scripts in head of your html and nothing else. For Css
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
For Js
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
The link to get this code is as https://getbootstrap.com/docs/4.0/getting-started/introduction/
来源:https://stackoverflow.com/questions/65723185/bootstrap-4-5-3-navbar-toggle-is-not-working