Bootstrap 5 "Nav-bar" collapse does not work - html

Base code:
<?php
session_start();
if ((!isset($_SESSION['valid']) == true)) {
unset($_SESSION['valid']);
header('location:index.php');
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Noticias sobre Vacina - Digital</title>
<!-- Bootstrap-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/css/bootstrap.min.css" integrity="sha512-F7WyTLiiiPqvu2pGumDR15med0MDkUIo5VTVyyfECR5DZmCnDhti9q5VID02ItWjq6fvDfMaBaDl2J3WdL1uxA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div class="cover-container d-flex w-100 h-100 mx-auto flex-column">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">Noticias sobre a vacina</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="home.php"><i class="fas fa-home"></i> Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="cadastro_noticia.php"><i class="fas fa-clipboard-list"></i> Cadastro de noticia </a>
</li>
<li class="nav-item dropdown">
</ul>
<form class="form-inline my-2 my-md-0">
<a class="nav-link active" href="index.php"><i class="fas fa-sign-out-alt"></i>Sair</a>
</form>
</div>
</div>
</nav>
<div id="wrapper" class="toggled" style="margin-left: 5%; display: inline;">
<div class="container-fluid" id="conteudo">
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.0/js/bootstrap.bundle.min.js" integrity="sha512-PqRelaJGXVuQ81N6wjUrRQelCDR7z8RvKGiR9SbSxKHPIt15eJDmIVv9EJgwq0XvgylszsjzvQ0+VyI2WtIshQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- <script src="js/noticia.js"></script> -->
</body>
</html>
I've tried redirecting, using other CDNs and other factors, but nothing works, none makes the collapse work. I would like some help as I have no idea why it is not working.
Who can help me and also explain why, I would appreciate it.

You have to change the data-toggle to data-bs-toggle and use data-bs-target attribute. Add the ID in the collapse div. That's all.
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse" id="collapse">

Related

How to justify content on navbar (Bootstrap 5)

I currently have a very minimal navbar set up with Bootstrap 5.
With navigation bars, there is both the 'navbar-brand' and nav links.
I want my brand/logo to be all the way on the far left, while all the navbar-nav links to be all the way to the right.
This could be achieved with flexbox and justify-content-between
However I have 0 clue where the navbar flex properties come into play, so therefore I am not sure where or what to change to achieve this effect
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#"><img src="images/brand.png"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-link active" aria-current="page" href="#">Home</a>
<a class="nav-link" href="#">About</a>
<a class="nav-link" href="#">Services</a>
<a class="nav-link" href="#">Contact Us</a>
</div>
</div>
</div>
</nav>
Is this what you want ? Indeed, justify-content-between is very useful for that. You have to use this style for the parent div and to put the children elements you want inside it.
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<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>
</head>
<body>
<nav
class="navbar d-flex justify-content-between fixed-top navbar-expand-lg navbar-light bg-light p-2"
>
<a class="navbar-brand align-self-center" href="#"><img src="images/brand.png" /></a>
<button
class="navbar-toggler align-self-center"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarNavAltMarkup"
aria-controls="navbarNavAltMarkup"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav text-end pe-1">
<a class="nav-link active" aria-current="page" href="#">Home</a>
<a class="nav-link" href="#">About</a>
<a class="nav-link" href="#">Services</a>
<a class="nav-link" href="#">Contact Us</a>
</div>
</div>
</nav>
</body>
</html>

Navbar when clicked is not redirecting to another page bootstrap 5

The issue is that when I click the navbar item it's not redirecting to the page and not giving any feedback. But when I delete the bootstrap.bundle.min.js it's working as it should be, but the expand button for the navbar when it's collapsed is not working.
<!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.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<title>Document</title>
<style>
.nav{
margin-bottom: 0px !important;
margin-top: 0px !important;
}
</style>
</head>
<body>
<!--Heading Navbar-->
<header class="border-bottom site-header sticky-top bg-white">
<nav class="navbar navbar-light navbar-expand-lg bg-white">
<div class="container-fluid">
<div class="d-flex flex-grow-1">
<a href="#" class="navbar-brand col-md-3 bg-white">
<img src="logo.jpg" class="img-fluid">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navNavbar" aria-controls="navNavbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse flex-grow-1 text-right" id="navNavbar" data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show">
<ul class="navbar-nav ms-auto flex-nowrap">
<li class="nav-item">
<a class="nav-link px-2 m-2 link-dark" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link px-2 m-2 link-secondary" href="about.html">About</a>
</li>
<li class="nav-item">
<a class="nav-link px-2 m-2 link-secondary" href="products.html">Products</a>
</li>
<li class="nav-item">
<a class="nav-link px-2 m-2 link-secondary" href="contactus.html" >Contact Us</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<!--Content-->
<!--Necessary Scripts-->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
</body>
</html>
The problem is the data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show" on the navbar-collapse div. Remove it and the navigation will work fine.
<div class="collapse navbar-collapse flex-grow-1 text-right" id="navNavbar" data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show">
<ul class="navbar-nav ms-auto flex-nowrap">
...
</ul>
</div>
Demo
Also, jQuery is not required for Bootstrap 5

Navbar donesn't Collapse Boostrap

when i open my html file i don't find the collapse button on the navbar. The button for collapsing does not appear
here is my html code :
<!DOCTYPE html>
<html>
<head>
<title>BoostUp - Boostez vos projets</title>
<link href="/assets/css/boostrap/bootstrap.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./assets/css/heroes.css">
<link rel="stylesheet" href="./assets/css/style.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="/assets/img/logo.png" alt="" width="30" height="24" class="d-inline-block align-text-top">
BoostUp
</a>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.html">Accueil</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Référencement</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Posts</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
<script src="./assets/js/jquery.js"></script>
<script src="/assets/js/booststrap/bootstrap.bundle.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="./assets/js/firestart.js"></script>
</body>
</html>
Ps : i'm on bootstrap 5
You forgot to include the toggler button.
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
Toggler

Problems of bootstrap navigation's menu and logo

1: I want to change size of logo and name in bootstrap navigation.
2: I have navigation menu, but it not appearing.
Navbar:
<nav class="navbar navbar-expand-lg py-4 fig-nav">
<div class="container">
<a href="#" class="navbar-brand">
<!-- Logo Image -->
<img src="./assets/logo.svg" width="50" height="50" alt="" class="d-inline-block
align-middle mr-3 img-responsive">
<!-- Logo Text -->
<span style="color:#ffffff" class="text-size text-decoration-none font-weight-
bold">Name</span>
</a>
<button class="navbar-toggler ml-2" type="button" data-toggle="collapse" data-
target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-
expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarSupportedContent" class="collapse navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item active"><a href="about.vue" class="nav-link nav-link:hover ">About
</a></li>
<li class="nav-item "><a href="products.vue" class="nav-link nav-
link:hover">Products</a></li>
<li class="nav-item "><a href="information.vue" class="nav-link nav-
link:hover">Information</a></li>
<li class="nav-item ">Jobs</li>
</ul>
</div>
</div>
</nav>
You made some mistakes in your code. Please check my code.
I am assuming you are using Bootstrap-5 where negative margins are disabled by default but can be enabled in Sass by setting $enable-negative-margins: true. Read their documentation - https://getbootstrap.com/docs/5.0/utilities/spacing/#negative-margin.
OR
use Bootstrap-4
OR
use your custom CSS.
Please check my code.
.navbar-nav{
margin-left: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<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>
<nav class="navbar navbar-dark bg-primary navbar-expand-lg py-4 fig-nav">
<div class="container">
<!-- Logo Image -->
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" width="50" height="50" alt="" class="d-inline-block
align-middle mr-3 img-responsive">
<!-- Logo Text -->
Name
<button class="navbar-toggler ml-2" type="button" data-toggle="collapse" data-
target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-
expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarSupportedContent" class="collapse navbar-collapse">
<ul class="navbar-nav">
<li class="nav-item active">About </li>
<li class="nav-item "><a href="products.vue" class="nav-link nav-
link:hover">Products</a></li>
<li class="nav-item "><a href="information.vue" class="nav-link nav-
link:hover">Information</a></li>
<li class="nav-item ">Jobs</li>
</ul>
</div>
</div>
</nav>
</body>
</html>

Bootstrap 4, material-kit - not working navbar-toggler

I have navbar with mobile navbar-toogler, but, this is not working. I'm using material-kit, and this is on my website. I'm want using this, because this is very cool css.
<head>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
<link href="https://hamsterofficial.eu/css/material-kit.css?v=2.0.4" rel="stylesheet"/>
<head>
<nav class="navbar navbar-color-on-scroll fixed-top navbar-expand-lg" color-on-scroll="100" id="sectionsNav">
<div class="container">
<div class="navbar-translate">
<a class="navbar-brand" href="">TEST WEBSITE </a>
<button class="navbar-toggler" type="button" data-toggle="collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
<span class="navbar-toggler-icon"></span>
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
test link
</li>
<li class="nav-item">
Blog
</li>
<li class="nav-item">
Autors
</li>
<li class="nav-item">
<i class="material-icons">input</i> Sign up
</li>
</ul>
</div>
</div>
</nav>
<script src="https://hamsterofficial.eu/js/core/jquery.min.js" type="text/javascript"></script>
<script src="https://hamsterofficial.eu/js/core/popper.min.js" type="text/javascript"></script>
<script src="https://hamsterofficial.eu/js/core/bootstrap-material-design.min.js" type="text/javascript"</script>