Why are my collapsible links not clickable in Bootstrap 5? [duplicate] - javascript

This question already has answers here:
Navbar dropdown (collapse) is not working in Bootstrap 5
(11 answers)
Closed 2 years ago.
When loading Bootstrap 4.5.3 via the CDN bundle:
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
the following dropdown works great:
<!-- Nav Item - Pages Collapse Menu -->
<li class="nav-item">
<a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseTwo"
aria-expanded="true" aria-controls="collapseTwo">
<span>AAAA</span>
</a>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<h6 class="collapse-header">BBBB</h6>
<a class="collapse-item" href="CCCC.html">CCCC</a>
<a class="collapse-item" href="DDDD.html">DDDD</a>
</div>
</div>
</li>
However, when I try to upgrade the Bootstrap verson to 5.0.0 via the CDN bundle:
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
Then the dropdown is no longer clickable. Why is this please?
FYI, I am using a clean install of the theme https://startbootstrap.com/theme/sb-admin-2 (source code available on GitHub: https://github.com/startbootstrap/startbootstrap-sb-admin-2), the index.html. Originally, it mentioned:
<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
But I noted the version of the /bootstrap.bundle.min.js (4.5.3) and it still worked without problems via the Bootstrap 4.5.3 CDN bundle, as described above.
That is, everything worked great if using:
<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
I did not make any other changes to any of the cleanly installed files (see GitHub repository above), other than that last line, and everything kept working.
Then, subsequently, the only change I made, somehow destroying the dropdown, is that I changed that last line into the following (to upgrade to Bootstrap 5.0.0):
<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
Why does this destroys the dropdown links? What tool can I use to troubleshoot this? I don't see any errors in my Firefox Developer Console.
Snippet (Bootstrap 4.5.3)
A full snippet of the working code (with 4.5.3) would be the following:
<!DOCTYPE html>
<head>
<!-- Standard Bootstrap CSS (4.3.1) via CDN -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">
<!-- Nav Item - Pages Collapse Menu -->
<li class="nav-item">
<a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#collapseTwo"
aria-expanded="true" aria-controls="collapseTwo">
<span>Components</span>
</a>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<h6 class="collapse-header">Custom Components:</h6>
<a class="collapse-item" href="buttons.html">Buttons</a>
<a class="collapse-item" href="cards.html">Cards</a>
</div>
</div>
</li>
</ul>
<!-- End of Sidebar -->
<!-- JQuery (3.5.1) and Bootstrap (4.5.3) JS bundle via CDN -->
<script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
</body>
</html>
If you change the last script line, to upgrade to Bootstrap 5.0.0, then the collapsing does no longer work:
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
Any help to make me understand a bit more how to port this code to Bootsrap 5, would be greatly appreciated. Do I even need JQuery for this?

Bootstrap 5 doesn't require jQuery, but you can still use it.
If you compare your code to the docs for Collapse you can see that here was an attribute name change from data-toggle to data-bs-toggle for Bootstrap 5. Also, anchors use the href attribute to set the target, not a data attribute. If you fix those things it works.
<!DOCTYPE html>
<head>
<!-- Standard Bootstrap CSS (5.0.0) via CDN-->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
</head>
<body>
<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion"
id="accordionSidebar">
<!-- Nav Item - Pages Collapse Menu -->
<li class="nav-item">
<a class="nav-link collapsed" href="#collapseTwo"
data-bs-toggle="collapse" aria-expanded="true" aria-controls="collapseTwo">
<span>Components</span>
</a>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo"
data-parent="#accordionSidebar">
<div class="bg-white py-2 collapse-inner rounded">
<h6 class="collapse-header">Custom Components:</h6>
<a class="collapse-item" href="buttons.html">Buttons</a>
<a class="collapse-item" href="cards.html">Cards</a>
</div>
</div>
</li>
</ul>
<!-- End of Sidebar -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
</body>
</html>

Related

No responsive links in bootstrap 4

What would make links non responsive in bootstrap? My links won't switch through my pages as they would do live. Any ideas ?
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<nav class="navbar navbar-dark bg-dark navbar-expand-sm">
<div class="container ">
<a class="navbar-brand d-none d-sm-inline-block fixed-top" href="#">Larry J designs</a>
<ul class="navbar-nav ">
<li class="nav-item "><a class ="nav-link active" href="index.html">Home</a></li>
<li class="nav-item"> <a class ="nav-link " href="about.html">About</a></li>
<li class="nav-item"> <a class ="nav-link" href="portfolio.html">Portfolio</a></li>
<li class="nav-item"> <a class ="nav-link" href="services.html">Services</a></li>
</ul>
<div class="clearfix">
<ul class="navbar-nav ">
<li class="nav-item "><a class ="nav-link active" href="index.html">Home</a></li>
<li class="nav-item"> <a class ="nav-link " href="about.html">About</a></li>
<li class="nav-item"> <a class ="nav-link" href="portfolio.html">Portfolio</a></li>
<li class="nav-item"> <a class ="nav-link" href="services.html">Services</a></li>
</ul>
</div>
</div>
</nav>
<!-- navbar-nav -->
<div class="container">
<section class="container" id ="mainpage">
<div class ="row">
<article class="col-8" id="bio">
<h1>Welcome to Larry J designs </h1>
<p class="justify-content-center">Hello, I'm Larry J , I currently live in the DC Metro area , I also love working on art in my spare time. As a teen in high I use to love to draw and build websites , Currently, I work a full time job like most , however in my spare time I love working on learning web design and drawing . Life has a long road to success , but on the road there are that you have to learn to get to the next level. </p></article>
<section class="col-sm-4">
<div class="row no-gutters">
<div class="col"><img src="about-thumbnail-placeholder.png" alt="larryphoto
" class="img-thumbnail">
</div>
</div>
</section>
</div>
</section>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
You're not using rows or columns and this will have a major effect on the responsiveness of Bootstrap.
You need to look into the Bootstrap Grid system, I advise reading through this page and applying these practices to your code:
https://getbootstrap.com/docs/4.0/layout/grid/
First of all, you should note that non responsive has a different meaning in the world of code, not just the simple 'not working' definition, but also meaning the layout will adapt and respond to the device and browser sizes, this is Responsive Design.
I believe that your problem is occuring from the title overlapping the other links, stopping them from ever interacting with the mouse, only the title will interact. You can look into Chrome's Dev Tools using the right click Inspect option on the links. This happens because the title <a> has a fixed-top class. Removing this solves the issue.
From:
<a class="navbar-brand d-none d-sm-inline-block fixed-top" href="#">Larry J designs</a>
To:
<a class="navbar-brand d-none d-sm-inline-block" href="#">Larry J designs</a>
I highly suggest you read up on the Bootstrap 4 Docs to get a grasp and understand how everything works and how to use the fixed-top class if you were trying to make the nav fixed. Also, looking at the examples and inspecting their code help too.

Bootstrap 4 navbar not collapsing on large screen

I am trying to implement a Navbar using Bootstrap 4. Currently, the Navbar correctly collapses when the viewport is shrunk to mobile size. However, when attempting to toggle menu, nothing happens. The jsFiddle example demonstrates this behavior. I have attached the HTML as well.
Steps I have taken:
Removing all custom CSS
Ensuring jQuery link is before Bootstrap JS file
Script tags in the header and the footer
Copy and paste exact examples from Bootstrap Docs (and I get the same behavior)
Ensuring that JS is being used in the Chrome browser
Validated HTML using WC3 validator
And of course, read various posts on SO about this issue but none lead to a resolution
jsFiddle link https://jsfiddle.net/u7v5jba9/
<title>Site title</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<body>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light">
<a class="navbar-brand" href="#">
<i class="fa fa-globe" aria-hidden="true"></i> Brand Name
</a>
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<i class="fa fa-angle-double-down"></i>
</button>
<div class="navbar-collapse collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">Link 1</li>
<li class="nav-item">Link 2</li>
<li class="nav-item">Link 3</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item">Sign In</li>
<li class="nav-item">Register</li>
<li class="nav-item">Log Out</li>
</ul>
</div>
</nav>
</div>
<div class="container">
<nav class="navbar navbar-inverse fixed-bottom text-center">
<h6 class="text-light text-center">Footer</h6>
</nav>
</div>
<!-- Scripts -->
<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://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
</body>
You need to include Popper as per the Getting Started Docs.
Use these for your scripts instead.
<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.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
Updated working Fiddle: https://jsfiddle.net/u7v5jba9/1/
Advice: In future, always open the dev inspector console in your browser to find any error messages.
You can also change the bootstrap reference to the bundled version - bootstrap.bundle.min.js - which includes popper.js.
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.bundle.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
Fiddle: https://jsfiddle.net/smoore4/m2dLp71q/
As #Anand Rockzz correctly points out, you still need to add jQuery before this reference.
This happens when you miss the order of scripts.
You should always include scripts in this order
jquery.js
popper.js
bootstrap.js
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
This might be helpful ...Since Bootstrap 5 there is a slight change in how collapse works... see code `
<button type="button" class="btn btn-primary btn-lg" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">DATA STRUCTURES & ALGORITHMS JS</button>
<div class="collapse" id="collapseExample" >
<form class="form-inline" id="form">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>

Bootstrap 4 Dropdown Menu not working?

I copied the official Bootstrap 4 example for dropdown menus but it is not working, that is nothing is dropped down.
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
Edit: In case anyone else is having this problem, I believe the solution for OP was that he had not imported popper.js.
Check that jQuery and all the relevant Bootstrap components are there. Also check the console and make sure there are no errors.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-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 active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap 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.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<-- Always remember to call the above files first before calling the bootstrap.min.js file -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
</body>
</html>
try to add these lines at the end of the file
<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>
</body>
</html>
Add this code to your jquery
$('.dropdown').click(function(){
$('.dropdown-menu').toggleClass('show');
});
Assuming Bootstrap and Popper libraries were installed using Nuget package manager, for a web application using Visual Studio, in the Master page file (Site.Master), right below where body tag begins, include the reference to popper.min.js by typing:
<script src="Scripts/umd/popper.min.js"></script>
Here is an image to better display the location:
Notice the reference of the popper library to be added should be the one inside umd folder and not the one outside on Scripts folder.
This should fix the problem.
include them with this order
this will work
i dont know why :D
<!-- jQuery -->
<script src="js/jquery-3.4.1.min.js"></script>
<!-- Popper -->
<script src="js/popper.min.js"></script>
<!-- Bootstrap js -->
<script src="js/bootstrap.min.js"></script>
It's an issue with popper.js file. What I found at the official site was that bundle files include popper in itself but not jquery. I managed to fix it by adding link to these files:
bootstrap.bundle.js
bootstrap.bundle.min.js
I removed popper.js however since it comes within the bundle file.
Via JavaScript
Call the dropdowns via JavaScript:
Paste this is code after bootstrap.min.js
$('.dropdown-toggle').dropdown();
Also, make sure you include popper.min.js before bootstrap.min.js
Dropdowns are positioned thanks to Popper.js (except when they are contained in a navbar).
Make sure to include the Bootstrap CSS either via the Bootstrap CDN
or download it and link it locally
I used NuGet to install BootStrap 4. I was also having issues with it not displaying the Dropdown on click. It kept throwing an error in jquery base on what the Chrome console was telling me.
I originally had the following
<%-- CSS --%>
<link type="text/css" rel="stylesheet" href="/Content/bootstrap.css" />
<%-- JS --%>
<script type="text/javascript" src="/Scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/Scripts/bootstrap.min.js"></script>
But I changed it to use the bundled version instead and it started to work
<%-- CSS --%>
<link type="text/css" rel="stylesheet" href="/Content/bootstrap.css" />
<%-- JS --%>
<script type="text/javascript" src="/Scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/Scripts/bootstrap.bundle.min.js"></script>
add this line of code to the end of the body tag
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
A simple answer is to replace this line:
<script type="text/javascript" src="your_directory/bootstrap.min.js"></script>
for this other:
<script type="text/javascript" src="your_directory/bootstrap.bundle.min.js"></script>
This is my solution
I just downloaded jquery's latest version from their official website and then added it as a js file in my project folder and then to my HTML file. After that it was working fine for me
You need to enqueue the script bootstrap.js or bootstrap.min.js. I had the same problem with bootstrap 4.5.3 and the menu worked when I enqueued one of the above scripts. It can be either.
It needs to be /bootstrap.js, not /bootstrap.min.js.

Bootstrap working on Local Host but not on online server

The code was working perfectly on local host with xampp. All I've done is upload it to a server and now it's not working.
I uploaded all the BS files as well. I also fixed the href links to be '..../js/bootstrap.min.js' etc. No images load and nor does bootstrap I do not think. The reason I think the problem comes from Bootstrap is because all the text/buttons still appear, they just aren't customised with the css/JS as BS does.
They are php files.
This is a link to the site: http://www.johnnythyroid.com.
I'm only new and this is just for learning so all advice is much appreciated.
This is the relevant code I think, I deleted a lot of the stupid text to make it shorter:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Jod</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel='stylesheet' type='text/css' href="johnnythyroidcom.ipage.com/css/custom icons.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="johnnythyroidcom.ipage.com/js/bootstrap.min.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-custom navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only"> Navbar toggle </span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="johnnythyroidcom.ipage.com/dansite1.php">Some Name</a>
</div>
<div class="navbar-collapse collapse" style="line-height:21px; height:140px;"> <!-- added this to prevent change of navbar height when switching between login/logout screens -->
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Account<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dropdown-header"></li>
<li>Login</li>
<li>Create Account</li>
<!-- <li class="divider"></li>
<li class="dropdown-header">Portfolio</li>
<li>Portfolio 1</li>
<li>Portfolio 2</li> add divider to split up a drop down menu -->
</ul>
</li>
<li class="navbar-text pull-right signedin"> Welcome, Guest! </li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="jumbotron text-center">
<h1> The </h1>
<p> A simgn </p>
Bg
ng
</div>
<div class="row-same-height">
<div class="col-md-4"> <!-- works on a 12 point grid system - columns need to add up to 12 in a row-->
<a href="johnnythyroidcom.ipage.com/rocket.php" class="thumbnail home-thumb">
<img src="johnnythyroidcom.ipage.com/Img/first rocket.jpg" style="max-height:250px" alt="First rocket theme"/>
</a>
<h3> Rjj </h3>
<p>sum dolor sit amet.</p>
</p>
View more
</div>
<div class="col-md-4"> <!-- works on a 12 point grid system - columns need to add up to 12 in a row-->
<a href="johnnythyroidcom.ipage.com/stars.php" class="thumbnail home-thumb">
<img src="johnnythyroidcom.ipage.com/Img/sky.jpg" style="max-height:250px" alt="sky theme"/>
</a>
<h3> Ss </h3>
<p>Lorenim.</p>
View more
</div>
<div class="col-md-4"> <!-- works on a 12 point grid system - columns need to add up to 12 in a row-->
<a href="johnnythyroidcom.ipage.com/sky.php" class="thumbnail home-thumb">
<img src="johnnythyroidcom.ipage.com/Img/stars.jpg" style="min-height:227px" alt = "Star theme"/>
</a>
<h3> y </h3>
<p>Lorenim.</p>
View more
</div>
</div>
</div>
<div class="navbar navbar-inverse navbar-fixed-bottom" role="navigation">
<div class="container">
<div class="navbar-text pull-left">
<p> aaaaaa </p>
</div>
<div class="navbar-text pull-right">
<i class="fa fa-facebook-square fa-2x"></i>
<i class="fa fa-twitter fa-2x"></i>
<i class="fa fa-google-plus fa-2x"></i>
</div>
</div>
</div>
Try this
change
<img src="johnnythyroidcom.ipage.com/Img/first rocket.jpg" style="max-height:250px" alt="First rocket theme">
into
<img src="http://johnnythyroidcom.ipage.com/Img/first rocket.jpg" style="max-height:250px" alt="First rocket theme">
add http:// to your all images src
Check the console for errors.
It says, Bootstrap's JavaScript requires jQuery, As I could see, You have included it and it is loaded correctly. Include that file before including bootstrap.min.js
Also correct that path of images. Your request url becomes: http://www.johnnythyroid.com/johnnythyroidcom.ipage.com/Img/first%20rocket.jpg which is incorrect.
Note: Just a blind guess, Incorrect path could be because of .htaccess
when reffering 3rd party include css or jss
you have to use https if your server is using https
else use http
for example you are accessing your site http://yoursite.com or http://localhost
then http://getbootstrap.com/css/bootstrap.min.js or css will work
that is why it works on localhost
but if you use https for yoru site https://yoursidte.com
then http://getbootstrap.com/css/bootstrap.min.js or css will not work
you will have to user https
e.g https://getbootstrap.com/css/bootstrap.min.js or css
THIS WAS THE CASE WHY MY menu were wroking on localcomputer but not over https , after changing from http to https://getbootstrap.com/css/bootstrap.min.js or css now it is working ..
all these files can be in different locations
for example you may save bootstrap.min.css in your site folder in case you edited that file ..

Navbar dropdown menu (using bootstrap) non functional

After following a tutorial on youtube about implementing a simple navigation menu I'm having an issue getting a dropdown menu to display and collapse two additional links. Can't seem to figure out the problem. Do I need to link to another stylesheet or .js file?
<html>
<head>
<title>None</title>
<link type="text/css" rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<!--Fixed Navbar with dropdown -->
<div class ="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle"collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img class="logo" src="images/om_logo_2.png">
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
Opportunities <b class="caret"></b>
<ul class="dropdown-menu">
<li>HGV & Lorry Delivery</li>
<li>Domestic Parcel & Package Courier</li>
</ul>
</li>
<li>Vehicle Hire</li>
<li>Contact Us</li>
</ul>
</div>
</div>
...
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>
You are not referencing the jquery library
like in the bootstrap example here
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
Change this..
<button type="button" class="navbar-toggle" data-toggle"collapse" data-target=".navbar-collapse">
to
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
Working on Bootply: http://bootply.com/103529

Categories

Resources