I'm using Twitter Boostrap 4 and have a navbar with 2 menus :
one menu for the general navigation
one menu for the account
On small devices, no problem : the two togglers are displaying correctly
On large devices, i want to show only the general navigation and not the account navigation. My problem : the account navivation is showing and i don't know how to hide it on large devices ?
<!-- logo -->
<a class="navbar-brand" href="#" class="d-inline-block align-top">
<img src="https://www.n9ws.com/images/upload/google-220118055200.png" />
</a>
<span class="d-none d-sm-inline" style="font-size:17px;text-shadow: 0.15em 0.15em #333;display:inline;color:white"><strong>Calendrier</strong> collaboratif des <strong>stages d'Aïkido</strong> en <strong>France</strong></span>
<!-- global menu toggle -->
<button class="navbar-toggler order-first" 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>
<!-- account toggle -->
<button class="navbar-toggler" style="padding: 0.55rem 0.70rem;" type="button" data-toggle="collapse" data-target="#navbarMonCompte" aria-controls="navbarMonCompte" aria-expanded="false" aria-label="Toggle navigation">
<i class="fa fa-user"></i>
</button>
<!-- account -->
<div class="collapse navbar-collapse justify-content-end" id="navbarMonCompte">
<ul class="navbar-nav float-right text-right">
<li class="nav-item ">
<a class="nav-link" href="#">Change email</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Change password</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Disconnect</a>
</li>
</ul>
</div>
<!-- gloab menu -->
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item ">
<a class="nav-link <?php echo ($this->menuSelected == 'accueil') ? 'active' : '';?>" href="/index2/index/">Accueil <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link <?php echo ($this->menuSelected == 'calendrier') ? 'active' : '';?>" href="/calendrier2/calendrier/">Calendrier</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Enseignants</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Vidéos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Comptes-rendus</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">
A propos
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Change email</a>
<a class="dropdown-item" href="#">Change password</a>
<a class="dropdown-item" href="#">Disconnect</a>
</div>
</li>
</ul>
<div class="form-inline my-2 my-lg-0">
<button type="button" class="btn btn-sm my-2 my-sm-0 btn-primary" data-toggle="modal" data-target="#my-modal-connexion">
Connexion
</button>
</div>
</div>
Have you got an idea ?
Thank you.
Eric
Target the navbar you want to hide by its id and give it a style of display:none to hide it on bigger devices i.e. min-width: 992px.
For eg: If you want to hide navbarMonCompte. The css will be as shown below.
#media only screen and (min-width: 992px) {
#navbarMonCompte {
display: none !important;
}
}
EDIT - To answer OP's new question in comments
On small devices, if i click on the 'account toggler" then on the 'global menu toggler', the 2 dropdown are shown. Is it possible to hide the other dropdow when a dropdown is shown ?
$('button[data-target=my-modal-connexion]').click(function() {
if($('#navbarSupportedContent').hasClass('show'))
$('#navbarSupportedContent').removeClass('show');
});
The above-given jQuery will check if the navbar is open or not when the account toggler is clicked. If it is open, it will be closed.
Try adding a hide-account class to the account button and put this into your css.
#media only screen and (min-width: 992px) {
.hide-account {
display: none;
}}
jsfiddle: https://jsfiddle.net/sfto2qhw/1/
You need to add d-block d-md-none to your account Toggler button you can use d-sm-none or d-lg-none instead of d-md-none as per your breakpoint
<!-- logo -->
<a class="navbar-brand" href="#" class="d-inline-block align-top">
<img src="https://www.n9ws.com/images/upload/google-220118055200.png" />
</a>
<span class="d-none d-sm-inline" style="font-size:17px;text-shadow: 0.15em 0.15em #333;display:inline;color:white"><strong>Calendrier</strong> collaboratif des <strong>stages d'Aïkido</strong> en <strong>France</strong></span>
<!-- global menu toggle -->
<button class="navbar-toggler order-first" 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>
<!-- account toggle -->
<button class="navbar-toggler d-block d-md-none" style="padding: 0.55rem 0.70rem;" type="button" data-toggle="collapse" data-target="#navbarMonCompte" aria-controls="navbarMonCompte" aria-expanded="false" aria-label="Toggle navigation">
<i class="fa fa-user"></i>
</button>
<!-- account -->
<div class="collapse navbar-collapse justify-content-end" id="navbarMonCompte">
<ul class="navbar-nav float-right text-right">
<li class="nav-item ">
<a class="nav-link" href="#">Change email</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Change password</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Disconnect</a>
</li>
</ul>
</div>
<!-- gloab menu -->
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item ">
<a class="nav-link <?php echo ($this->menuSelected == 'accueil') ? 'active' : '';?>" href="/index2/index/">Accueil <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link <?php echo ($this->menuSelected == 'calendrier') ? 'active' : '';?>" href="/calendrier2/calendrier/">Calendrier</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Enseignants</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Vidéos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Comptes-rendus</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">
A propos
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Change email</a>
<a class="dropdown-item" href="#">Change password</a>
<a class="dropdown-item" href="#">Disconnect</a>
</div>
</li>
</ul>
<div class="form-inline my-2 my-lg-0">
<button type="button" class="btn btn-sm my-2 my-sm-0 btn-primary" data-toggle="modal" data-target="#my-modal-connexion">
Connexion
</button>
</div>
</div>
Related
I've been searching for it all day and couldn't find a solution, so I hope I won't look like an idiot when in 2 minutes someone will post an answered link for the exact question.
I am trying to create a navbar like on steamdb
Where the search box remains after the navbar collapse and is just reduced in size.
But I ran into the problem where if I set the navbar to <nav class="navbar-expand-lg" </nav> then when it collapses it split into 3 lines, one for the brand, one for search, and one for toggle dropdown.
If I remove the "-lg" then it doesn't split, but then it also doesn't change the items to toggle.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="/">My Company Name</a>
<form class="d-flex w-100 d-inline-block">
<div class="input-group">
<input class="form-control no-border" type="text" placeholder="search for game..." id="example-search-input">
<span class="input-group-append">
<button class="btn rounded-pill" type="button">
<i class="bi bi-search"></i>
</button>
</span>
</div>
</form>
<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 ms-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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
content
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="/test1">test1</a></li>
<li><a class="dropdown-item" href="/test2">test2</a></li>
<li><a class="dropdown-item" href="/test3">test3</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Donate</a>
</li>
</ul>
</div>
</div>
</nav>
https://www.codeply.com/p/uaWJpGVRED
Please help, I've been stuck on this all day
You need to use 2 inner divs inside the container. Make them both w-100, and the first one d-flex so that the brand and form layout horizontally...
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<div class="d-flex w-100">
<a class="navbar-brand" href="/">My Company Name</a>
<form class="d-flex w-100 d-inline-block">
<div class="input-group">
<input class="form-control no-border" type="text" placeholder="search for game..." id="example-search-input">
<span class="input-group-append">
<button class="btn rounded-pill" type="button">
<i class="bi bi-search"></i>
</button>
</span>
</div>
</form>
<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>
<div class="collapse navbar-collapse w-100" id="navbarSupportedContent">
<ul class="navbar-nav ms-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 dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> content </a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="/test1">test1</a></li>
<li><a class="dropdown-item" href="/test2">something</a></li>
<li><a class="dropdown-item" href="/test3">bla bla</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Donate</a>
</li>
</ul>
</div>
</div>
</nav>
Demo
I have a simple bootstrap 4 menu and would like to expand the submenu by default for mobile users. How would I accomplish this (first preference is for a CSS only solution)?
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="http://www.mywebsite.com"> <img src="https://www.mywebsite.com/logo.png" style="width:75px;"> My Website</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="~/">Home <span class="sr-only">(current)</span></a>
</li>
<!-- expand this menu by default for mobile users -->
<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">
sub menu
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="~/Page 1">Page 1</a>
<a class="dropdown-item" href="~/Page 2">Page 2</a>
<a class="dropdown-item" href="~/Page 3">Page 3</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="~/Page 4">Page 4</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Page 5</a>
</li>
</ul>
</div>
Add show to <li class="nav-item dropdown">.
<!-- expand this menu by default for mobile users -->
<li class="nav-item dropdown show">
Edit: Bootstrap 3 was open Bootstrap 4 is show
I'm newer to Bootstrap and have a question about my Navbar.
Here is my test site. TEST-DOMAIN
I'm currently using Bootstrap 4.3.1 with JQuery 3.4.1.
Menu looks and functions great on Desktop. Dropdown appears as expected. I added columns to the dropdown to make a Mega Menu of sorts.
When the site transitions over to mobile, the dropdown is appearing to the RIGHT of the parent menu item. Is there a way to make it appear BELOW the parent item and push the rest of the menu down below it?
I tried setting the dropdown to Display: absolute as found in other posts about this. But, while it shifts the dropdown to the left like I want, it floats it overtop of the rest of the menu. I would like it to align left, while pushing the rest of the menu below it.
Thanks for any help!
* EDIT - Adding code *
<!--Navbar-->
<nav id="navbar" class="navbar navbar-expand-lg navbar-dark nav-transparent sticky-top">
<div class="container">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#" style="margin-top: -5px;"><strong>Test Website</strong></a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-center">
<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 dropdown btn-group">
<a class="nav-link dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Services</a>
<div class="dropdown-menu dropdown" aria-labelledby="dropdownMenu1">
<div class="container">
<div class="row">
<div class="col-md-4">
<a class="dropdown-item" href="another-page.html">ANOTHER PAGE</a>
<a class="dropdown-item" href="pools.html">POOLS</a>
<a class="dropdown-item" href="test-10.html">TEST 10</a>
<a class="dropdown-item" href="test-5.html">TEST 5</a>
</div>
<div class="col-md-4">
<a class="dropdown-item" href="test-6.html">TEST 6</a>
<a class="dropdown-item" href="test-7.html">TEST 7</a>
<a class="dropdown-item" href="test-8.html">TEST 8</a>
<a class="dropdown-item" href="test-9.html">TEST 9</a>
</div>
<div class="col-md-4">
<a class="dropdown-item" href="yet-another-page.html">YET ANOTHER PAGE</a>
<a class="dropdown-item" href="awesome-page.html">AWESOME PAGE</a>
</div>
</div>
</div>
</div>
</li>
<li class="nav-item"><a class="nav-link" href="about.html">About Us</a></li>
<li class="nav-item"><a class="nav-link" href="gallery.html">Gallery</a></li>
<li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li>
<li class="nav-item"><a class="nav-link" href="kitchen-vision.html">KITCHEN VISION</a></li>
<li class="nav-item"><a class="nav-link" href="contact.html">Contact Us</a>
</li>
</ul>
</div>
</div>
I've removed all my custom CSS for the NavBar to make sure I wasn't doing something incorrect with my edits.
#media screen and (max-width: 768px) {
.mx-auto.d-flex {
margin: 0!important;
justify-content: space-between;
display: flex;
width: 100vw;
}
}
<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">
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="mx-auto d-flex">
<a class="navbar-brand" href="#">Test Website</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 ">
<li class="nav-item active">
<a class="nav-link" href="#">Home <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">
Services
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<div class="container">
<div class="row">
<div class="col-md-4">
<a class="dropdown-item" href="another-page.html">ANOTHER PAGE</a>
<a class="dropdown-item" href="pools.html">POOLS</a>
<a class="dropdown-item" href="test-10.html">TEST 10</a>
<a class="dropdown-item" href="test-5.html">TEST 5</a>
</div>
<div class="col-md-4">
<a class="dropdown-item" href="test-6.html">TEST 6</a>
<a class="dropdown-item" href="test-7.html">TEST 7</a>
<a class="dropdown-item" href="test-8.html">TEST 8</a>
<a class="dropdown-item" href="test-9.html">TEST 9</a>
</div>
<div class="col-md-4">
<a class="dropdown-item" href="yet-another-page.html">YET ANOTHER PAGE</a>
<a class="dropdown-item" href="awesome-page.html">AWESOME PAGE</a>
</div>
</div>
</div>
</div>
</li>
<li class="nav-item"><a class="nav-link" href="about.html">About Us</a></li>
<li class="nav-item"><a class="nav-link" href="gallery.html">Gallery</a></li>
<li class="nav-item"><a class="nav-link" href="faq.html">FAQ</a></li>
<li class="nav-item"><a class="nav-link" href="kitchen-vision.html">KITCHEN VISION</a></li>
<li class="nav-item"><a class="nav-link" href="contact.html">Contact Us</a>
</li>
</ul>
</div>
</div>
</nav>
I am having issues aligning a dropdown menu on the navbar-brand portion of the Bootstrap 4 Navbar. For some reason it is aligning to the top left of the page.
I have tried the following code below and am not sure how to go from there.
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container">
<a class="navbar-brand dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
WebsiteName
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/>WebsiteName</a>
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">Popular Subdomains</h6>
<a class="dropdown-item" href="/">Subdomain 2</a><a class="dropdown-item" href="/">Subdomain 3</a> <div class="dropdown-divider"></div>
<a class="dropdown-item" href="/">All Subdomains</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="/">Home Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/two-link/">Two Link</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0" action="/search">
<input class="form-control mr-sm-2" type="text" name="q" placeholder="Search">
</form>
</div>
</div>
</nav>
just curiosity , are you tring to make your brand is dropdown cause its a big mistake try to read this docs to see how its work
https://getbootstrap.com/docs/4.2/components/navbar/
you can also position your navbar by using float or flex alignment as you wish
<div class="container">
<nav class="navbar navbar-toggleable-lg fixed-top navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" 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>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse ">
<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>
</div>
I want to pull-right home, features, pricing, and dropdown link elements.
I was trying to add to ul class="pull-right" but its not working.
I also tried to add nabar-right class to ul section also nothing.
From the bootstrap documentation:
Align nav links, forms, buttons, or text, using the .navbar-left or
.navbar-right utility classes. Both classes will add a CSS float in
the specified direction. For example, to align nav links, put them in
a separate <ul> with the respective utility class applied.
So use the .navbar-right class on your <ul>
Example: https://jsfiddle.net/1s7j8srp/