Dropdown in toggler dont work / bootstrap - html

I have navbar with lot of lists. I want to use dropdown and toogler on mobile devices. Problem is when navbar is toggled dropdown menu after touch will close whole toogler.
<nav class="navbar navbar-expand-xl navbar-light sticky-top py-3 d-block" data-navbar-on-scroll="data-navbar-on-scroll">
<div class="container"><a class="navbar-brand" href="index.html"><img src="assets/img/gallery/logo-n.png" height="45" alt="logo" /></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon">
</span></button>
<div class="collapse navbar-collapse border-top border-lg-0 mt-4 mt-lg-0" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto pt-2 pt-lg-0 font-base">
<li class="nav-item px-2"><a class="nav-link active" aria-current="page" href="index.html">Domů</a></li>
<li class="nav-item dropdown zakldropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Základní škola
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Chrakteristika ZŠ</a></li>
<li><a class="dropdown-item" href="#">Organizace školního roku</a></li>
<li><a class="dropdown-item" href="#">Školská rada</a></li>
</ul>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="web-development.html">Mateřská škola</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Jídelna</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">EKOškola MŠ a ZŠ</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Družina</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Málinka z. s.</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Dokumenty</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Kontakty</a></li>
</ul>
</div>
</div>
</div>
</nav>

I once had the same problem. In my case I didn't add the following line in my code
<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>
Aswel make sure if you have this code you comment this part of code out
<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
-->
Make sure you have the template that they recommand: Starter template
https://getbootstrap.com/docs/5.0/getting-started/introduction/

<nav class="navbar navbar-expand-xl navbar-light sticky-top py-3 d-block" data-navbar-on-scroll="data-navbar-on-scroll">
<div class="container">
<a class="navbar-brand" href="index.html">
<img src="assets/img/gallery/logo-n.png" height="45" alt="logo" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon">
</span></button>
<div class="collapse navbar-collapse border-top border-lg-0 mt-4 mt-lg-0" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto pt-2 pt-lg-0 font-base">
<li class="nav-item px-2"><a class="nav-link active" aria-current="page" href="index.html">Domů</a></li>
<li class="nav-item px-2 dropdown zakldropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Základní škola
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Chrakteristika ZŠ</a></li>
<li><a class="dropdown-item" href="#">Organizace školního roku</a></li>
<li><a class="dropdown-item" href="#">Školská rada</a></li>
</ul>
</li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="web-development.html">Mateřská škola</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Jídelna</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">EKOškola MŠ a ZŠ</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Družina</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Málinka z. s.</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Dokumenty</a></li>
<li class="nav-item px-2"><a class="nav-link" aria-current="page" href="user-research.html">Kontakty</a></li>
</ul>
</div>
</div>
</nav>
I check it works but you forgot to close a tag

Related

bootstrap 4 nav bar not covering full width when dropdown

This is what my code looks like for the nav bar, when I press the dropdown button, this is how it will look like on my page
https://docs.google.com/document/d/1gHsqAZ9QTaJX4A-1PXrVVoXi2KWBWqa6YTA_-QtG8wo/edit?usp=sharing
<nav class="navbar navbar-expand-lg navbar-dark bg-color mb-3">
<a class="navbar-brand" href="/"><img src="/img/logo.png" alt="" width="100px" height="40px">RYCE</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="navbarSupportedContent">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link text-white" href="/">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">OUR CARS</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">SHOP PARTS</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">TEST DRIVE</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">SERVICING</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">SUPPORT</a>
</li>
<li class="nav-item dropdown">
STAFF
<div class="dropdown-menu">
Users Management
Bookings Management
Products Management
Orders Management
</div>
</li>
<li class="nav-item">
<a class="nav-link text-white" href=""><i style='font-size:24px' class='fas'></i></a>
</li>
<li class="nav-item dropdown">
<i class="material-icons"></i>
<div class="dropdown-menu">
LOGIN
SIGN UP
PROFILE
</div>
</li>
</ul>
</div>
</nav>
I have tried changing the width of the navbar and some of the bootstrap properties but none of my attempts have worked so far. I am unsure if the problem lies with the navbar or dropdown menu.
Thank you so much for all your inputs!
You can add .dropdown-menu-right to .dropdown-menu to align the dropdown to the right when it is shown -- this way it stops it from increasing the width of the page. Is this what you wanted?
Otherwise consider using Bootstrap collapse, I can change my example if you want!
body { height: 100vh }
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="bg-dark h-100">
<nav class="navbar navbar-expand-lg navbar-dark bg-danger bg-color mb-3">
<a class="navbar-brand" href="/"><img src="/img/logo.png" alt="" width="100px" height="40px"> RYCE</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="nav navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link text-white" href="/">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">OUR CARS</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">SHOP PARTS</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">TEST DRIVE</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">SERVICING</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="">SUPPORT</a>
</li>
<li class="nav-item dropdown">
STAFF
<div class="dropdown-menu dropdown-menu-right">
Users Management
Bookings Management
Products Management
Orders Management
</div>
</li>
<li class="nav-item">
<a class="nav-link text-white" href=""><i style='font-size:24px' class='fas'></i></a>
</li>
<li class="nav-item dropdown">
<i class="material-icons"></i>
<div class="dropdown-menu dropdown-menu-right">
LOGIN
SIGN UP
PROFILE
</div>
</li>
</ul>
</div>
</nav>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery#3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>

Bootstrap 5 Navbar stays collapsed

I copied everything from Bootstrap, but my navbar stays collapsed on mobile and tablet. When i click the icon, there is a movement, like they try to go up and down.
I attached the code below :
<nav class="navbar navbar-expand-lg navbar-dark ">
<div class="container-fluid ">
<!-- <a class="navbar-brand" href="#">Navbar</a> -->
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-flex justify-content-center" id="navbarNav">
<ul class="navbar-nav my-5 fs-5">
<li class="nav-item me-5">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item me-5">
<a class="nav-link" href="#">Tour List</a>
</li>
<li class="nav-item me-5">
<a class="nav-link" href="#">Tour Search</a>
</li>
<!-- LOGO -->
<img src="/images/Landing-logo.png" width="125px" alt="">
<!-- LOGO -->
<li class="nav-item ms-5">
<a class="nav-link" href="#">Desinations</a>
</li>
<li class="nav-item ms-5">
<a class="nav-link" href="#">Pages</a>
</li>
<li class="nav-item ms-5">
<a class="nav-link" href="#">Blog</a>
</li>
</ul>
</div>
</div>
</nav>
this is code snippet for responsive navbar you can adjust it accordingly.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>```

Add a droplist menu to a list item CSS

I wanted to add a droplist to the 4th element in my navbar .
Under "ESPACE PARTICULIER" I need to get 2 options .
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">A PROPOS NOUS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">COURS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">SERVICES</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ESPACE PARTICULIER</a>
</li>
<li class="nav-item">
<a class="button-highlight" href="#">Sign in</a>
</li>
</ul>
</div>
You are using Bootstrap so it's easy to do it Jus take alook in this Bootstrap Dropdown
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">A PROPOS NOUS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">COURS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">SERVICES</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown"role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">ESPACE PARTICULIER</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="button-highlight" href="#">Sign in</a>
</li>
</ul>
</div>
You need to look at the manual
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">A PROPOS NOUS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">COURS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">SERVICES</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">ESPACE PARTICULIER</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>

How to align navbar item to the right side (also in the data-toggle when minimizing)?

I want to create a navbar where the logout and contact button are on the right side.
In the mobile view the nav-items should be combined in a collapse toggle. This is my code so far:
Untitled
HeadlineCompany
Toggle navigation
<div class="collapse navbar-collapse" id="navcol-1">
<ul class="nav navbar-nav">
<li class="nav-item dropdown">
<a class="dropdown-toggle nav-link" data-toggle="dropdown" aria-expanded="false">All Items</a>
<div class="dropdown-menu">
<a class="dropdown-item">Item 1</a>
<a class="dropdown-item">Item 2</a>
</div>
</li>
<li class="nav-item"><a class="nav-link">Topics</a></li>
</ul>
</div>
<ul class="navbar-nav mr-auto">
<li class="nav-item"><a class="nav-link">Contact</a></li>
<li class="nav-item"><a class="nav-link">Logout</a></li>
</ul>
</div>
</nav>
And this is what it looks like:
actual normal page
actual mobile view
This is how it should look:
as it should be
Does anyone have a tip on how I can make this work?
Thank you!
This worked for me - add a <div> wrapper to the <ul> (towards the bottom of my pasted code).
Here is JSFiddle: https://jsfiddle.net/omartheman949/eykr71c4/
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">HeadlineCompany</a>
<button class="navbar-toggler" 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 class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#"><span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
All Items
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Topics</a>
</li>
</ul>
<div> <!-- ************ADD THIS DIV WRAPPER************ -->
<ul class="navbar-nav mr-auto">
<li class="nav-item"><a class="nav-link">Contact</a></li>
<li class="nav-item"><a class="nav-link">Logout</a></li>
</ul>
</div> <!-- ************ADD THIS DIV WRAPPER************ -->
</div>
</nav>

Center the img/logo and make the navbar items around the logo

I want to center the logo and have 2 navbar items from its left and the other 2 from the right. It will increase my website functionality and help with the more modern look. If someone could help me I would be really grateful, thanks a lot!!!
tried searching here i didnt find anything that was working for me.
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="index.html">
<img src="img\binet-logo1.png" height="70"width="100" alt=""></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<li class="nav-item">
<a class="nav-link" href="index.html">Дома</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Продукти
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="produkti.html">Ултразвучни системи</a>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="zanas.html">За Нас</a>
</li>
</li>
<li class="nav-item">
<a class="nav-link" href="C:\Users\Bojan\Desktop\BinetMedical\contact.html">Контакт</a>
</li>
</ul>
</div>
</div>
You can try using this code to get the logo in the middle and the nav links on the sides.
<nav class="navbar navbar-expand-md navbar-fixed-top navbar-dark bg-dark">
<div class="container">
<ul class="nav navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index.html">Дома</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Продукти
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="produkti.html">Ултразвучни системи</a>
</a>
</li>
</ul>
<ul class="nav navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="#"> <img src="img\binet-logo1.png" height="70"width="100" alt=""></a>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="zanas.html">За Нас</a>
</li>
<li class="nav-item">
<a class="nav-link" href="C:\Users\Bojan\Desktop\BinetMedical\contact.html">Контакт</a>
</li>
</ul>
</div>
</nav>
Each part is a seperate ul and i added the class mx-auto