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>
Related
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
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>
So I have been trying to create a lateral menu that has a logo right on top of it as well as a traditional navigation menu next to it. But I seem to have ran into a problems where I cannot put my logo inside the lateral menu and to align it. Here is the code I have so far that I am trying to use. My final goal is to have it like this mockup that of a page I have made, any help will be most welcome https://i.stack.imgur.com/wwcXT.png
<header>
<nav class="my-nav navbar navbar-light navbar-expand-lg">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-
target="#navbarsExample08" aria-controls="navbarsExample08" aria-expanded="false" aria-
label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-md-center" id="navbarsExample08">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown08" data-toggle="dropdown" aria-
haspopup="true" aria-expanded="false">ACTIVITES</a>
<div class="dropdown-menu" aria-labelledby="dropdown08">
<a class="dropdown-item" href="#">Rafting</a>
<a class="dropdown-item" href="#">Canooing</a>
<a class="dropdown-item" href="#">Parachute</a>
<a class="dropdown-item" href="#">Soufflerie</a>
<a class="dropdown-item" href="#">Saut elastique</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">OFFRES</a>
<li class="nav-item">
<a class="nav-link" href="#">EVENEMENTS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">A PROPOS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ESPACE HANDICAP</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CONTACT</a>
</li>
</li>
</ul>
</div>
</nav>
</div>
<nav class="navbar-lateral">
<ul>
<li class="logo">
<a href="" class="nav-link">
<img src="./img/so.png" alt="">
</a>
</li>
</ul>
</nav>
CSS for lateral bar
.navbar-lateral {
width: 5rem;
height: 100vh;
position: fixed;
background: white;
}
You can use Bootstrap built-in nav for the horizontal like you did and add a custom navbar to the lateral side with the logo inside it. Something like this:
HTML
<header>
<nav class="my-nav navbar navbar-light navbar-expand-lg">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-
target="#navbarsExample08" aria-controls="navbarsExample08" aria-expanded="false" aria-
label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-md-center" id="navbarsExample08">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown08" data-toggle="dropdown" aria-
haspopup="true" aria-expanded="false">ACTIVITES</a>
<div class="dropdown-menu" aria-labelledby="dropdown08">
<a class="dropdown-item" href="#">Rafting</a>
<a class="dropdown-item" href="#">Canooing</a>
<a class="dropdown-item" href="#">Parachute</a>
<a class="dropdown-item" href="#">Soufflerie</a>
<a class="dropdown-item" href="#">Saut elastique</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">OFFRES</a>
<li class="nav-item">
<a class="nav-link" href="#">EVENEMENTS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">A PROPOS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ESPACE HANDICAP</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CONTACT</a>
</li>
</li>
</ul>
</div>
</nav>
</div>
<div class="lateral-nav">
<img src="https://tkruger4.files.wordpress.com/2010/11/logo-2_rgb.jpg" alt="">
item
item
item
</div>
CSS
.lateral-nav {
position:absolute;top:0;left:0;width:100px;background:white;height:300px;display:flex;flex-direction:column;justify-content:flex-start;align-items:center;
}
img {
width:60px;height:60px;margin-top:10px;
}
.lateral-nav a {
writing-mode:vertical-lr;text-orientation:mixed;margin:10px 0;}
.navbar {
margin-top:10px;
}
Navber code:
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #FDFEFF;">
<div class="collapse navbar-collapse justify-content-center" id="navbarNav">
<a class="navbar-brand" href="#">
<img src="images\logo1.png" width="200" height="80" class="d-inline-block align-top" alt="">
</a>
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="navbar-nav dropdown">
<a class="nav-link dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Behandelingen
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="sportmassage.html">Sportmassage</a>
<a class="dropdown-item" href="#">Massagetherapie</a>
<a class="dropdown-item" href="#">Ontspanningsmassage</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Afspraak maken</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Tarieven</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
Bootstrap code:
<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">
Dropdown menu inside the navbar doesn't open, anyone an idea on how to fix this?
Not very experienced with bootstrap and don't now what the problem is.
Your button don't call your div
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<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>
</div>
your "aria-labelledby" does not match the button id "id="dropdownMenuButton""
it's in the bootstrap documentation
Try this for Bootstrap 4 dropdown navbar
<nav class="navbar navbar-expand-lg navbar-light" style="background-color: #fdfeff;">
<a class="navbar-brand" href="#">
<img src="images\logo1.png" width="200" height="80" class="d-inline-block align-top" alt="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navCollapse"
aria-controls="navCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-center" id="navCollapse">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="navbar-nav dropdown">
<a class="nav-link dropdown-toggle" type="button" id="dropdown01"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Behandelingen
</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="sportmassage.html">Sportmassage</a>
<a class="dropdown-item" href="#">Massagetherapie</a>
<a class="dropdown-item" href="#">Ontspanningsmassage</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Afspraak maken</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Tarieven</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
Nevermind I solved the issue, stupid mistake by not adding jquery
When I click on the dropdown menu this is always highlighted in blue. How can I fix this with Bootstrap or a change of my CSS?
With this CSS element I already tried to change the color:
.dropdown-item.active, .dropdown-item:active
color: red
background-color: darkviolet
HTML:
<nav class="nav-justified navbar-expand-xl navbar-light">
<div class="" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto nav-pills nav-fill">
<li class="nav-item active">
<a class="nav-link" href="home.html">Home<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="überuns.html">Über uns</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Konakt.html">Kontakt</a>
</li>
<li class="nav-item dropdown dropdown">
<a class="nav-link dropdown-toggle" href="Maschinen.html"
id="navbarDropdown" role="button" data-toggle="dropdown" aria-
haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-
enter code herelabelledby="navbarDropdown">
<a class="dropdown-item" href="1.html">Element 1</a>
<a class="dropdown-item" href="2.html">Element 2</a>
<a class="dropdown-item" href="3.html">Element 3</a>
<a class="dropdown-item" href="4.html">Element 4</a>
<a class="dropdown-item" href="5.html">Element 5</a>
<a class="dropdown-item" href="6.html">Element 6</a>
</div>
.dropdown-item:active use this
.dropdown-item:active{
color: red;
background-color: darkviolet}
<nav class="nav-justified navbar-expand-xl navbar-light">
<div class="" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto nav-pills nav-fill">
<li class="nav-item active">
<a class="nav-link" href="home.html">Home<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="überuns.html">Über uns</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Konakt.html">Kontakt</a>
</li>
<li class="nav-item dropdown dropdown">
<a class="nav-link dropdown-toggle" href="Maschinen.html"
id="navbarDropdown" role="button" data-toggle="dropdown" aria-
haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-
enter code herelabelledby="navbarDropdown">
<a class="dropdown-item" href="1.html">Element 1</a>
<a class="dropdown-item" href="2.html">Element 2</a>
<a class="dropdown-item" href="3.html">Element 3</a>
<a class="dropdown-item" href="4.html">Element 4</a>
<a class="dropdown-item" href="5.html">Element 5</a>
<a class="dropdown-item" href="6.html">Element 6</a>
</div>
The default css is generated from nav.scss
Add this into your custom css file to change background color :
.nav-pills .nav-link.active,
.nav-pills .show>.nav-link{
background:darkviolet
}
I would also suggest you to use custom class for navbar like my-custom-nav and use as parent for above css like :
.my-custom-nav .nav-link.active,
.my-custom-nav .show>.nav-link{
background:darkviolet
}