I can't seem to get the navbar logo to centre align with the nav-links centre below it. I'm sure I'm missing something simple, I've checked out a few other posts regarding this issue but all seem to be using older versions of bootstrap. I am currently using bootstrap 4.0.
Specifically, I want the logo on its own separate row, not on the same one as the links.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#"><img src="img/h-tech-logo-cropped.png"/></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="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Our Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Contact Us</a>
</li>
</ul>
</div>
It's a matter of using the flexbox and auto-margin utils as explained in the many other "Bootstrap 4 Navbar Center" questions...
The navbar is display:flex so use flex-column to make content stack
Use mx-auto for auto x-axis margins to center.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" >
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" 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" ></script>
<nav class="navbar navbar-expand navbar-light bg-light flex-column">
<a class="navbar-brand mx-auto" href="#"><img src="img/h-tech-logo-cropped.png"></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="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Our Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Contact Us</a>
</li>
</ul>
</div>
</nav>
Responsive demo on Codeply
Related "Bootstrap 4 Navbar Center" questions:
Bootstrap NavBar with left, center or right aligned items
Bootstrap 4 navbar with 2 rows
Center an element in Bootstrap 4 Navbar
How to center nav-items in Bootstrap?
Related
This question already has answers here:
Bootstrap navbar: nothing is displayed on smaller devices
(1 answer)
Bootstrap 5.0 Hamburger menu icon doesn't show up [duplicate]
(1 answer)
Closed 12 months ago.
Hello I'm using Bootstrap to create a website, however when I try to add the hamburger menu it doesn't appear when I bring the screen size down.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<a class="navbar-brand" href="#">Hello world</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#toggleMobileMenu" aria-controls="toggleMobileMenu" aria-expanded="false" aria-lable="Toggle Navigation">
<span class = "navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="toggleMobileMenu">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link link-dark" href="#">About us</a>
</li>
<li class="nav-item">
<a class="nav-link link-dark" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link link-dark" href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link link-dark" href="#">Book</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
It's the navbar-light class which specifies the background for the toggle button. Add that to the nav element.
Navbars require a wrapping .navbar with .navbar-expand{-sm|-md|-lg|-xl|-xxl} for responsive collapsing and color scheme classes.
https://getbootstrap.com/docs/5.1/components/navbar/#how-it-works
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<nav class="navbar navbar-light navbar-expand-lg">
<div class="container-fluid">
<a class="navbar-brand" href="#">Hello world</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#toggleMobileMenu" aria-controls="toggleMobileMenu" aria-expanded="false" aria-lable="Toggle Navigation">
<span class = "navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="toggleMobileMenu">
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link link-dark" href="#">About us</a>
</li>
<li class="nav-item">
<a class="nav-link link-dark" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link link-dark" href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link link-dark" href="#">Book</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
I followed this post as for close responsive menu "on click":
Bootstrap close responsive menu "on click"
But when I click on menu i.e. link it doesn't goes/move to intended div on page.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<nav class="navbar navbar-expand-lg navigation-wrap">
<div class="container">
<a class="navbar-brand" href="#"><img src="img/logo.png" height="60" alt=""> पोटोबा</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<i class="fas fa-stream navbar-toggler-icon"></i>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<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" data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show">Home</a>
<!-- added additional attributes to links data-bs-toggle="collapse" data-bs-target=".navbar-collapse" -->
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#about" data-bs-toggle="collapse" data-bs-target=".navbar-collapse.show">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#explore-food">Explore Food</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#testimonial">Reviews</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#faq">FAQ</a>
</li>
<li><button class="main-btn">1700 345 123</button></li>
</ul>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
check which version you are using of bootstrap data-bs-toggle is for bootstrap 5, if you are using bootstrap 4 the data attributes are different something like data-toggle and data-target
I want develop a navbar which content has space from left and right and it should support mobile, desktop screen side too, but I am unable to get it.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">eNno</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>
<li class="nav-item">
<a class="nav-link" href="#">Service</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Portifolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
This is the output of my code
How can I get it
You can insert a Bootstrap .container inside your <nav>. This will set the proper margins to the left and right. In addition, change navbar-nav mr-auto to navbar-nav ml-auto to align your navbar items to the right.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<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>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="#">eNno</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 ml-auto">
<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="#">Service</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Portifolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
This result looks like this:
The mobile navbar:
This question already has answers here:
Change navbar color in Twitter Bootstrap
(12 answers)
Closed 4 years ago.
I got a problem with my bootstrap nav bar. It wont color the way I want it too and I tried adding code even with the !import but I can't get it to work
<nav class="navbar navbar-expand-md navbar-ligt fixed-top sticky-navigation " style="background: green !important;">
<button class="navbar-toggler navbar-toggler-right" type="button" style="background: green !important;" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="ion-grid icon-sm"></span>
</button>
<a class="navbar-brand hero-heading" href="#">Jeroen Hooge</a>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#main">Product <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#features">Werk</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#pricing">Prijs</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#team">Team</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#blog">Blog</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#contact">Contact</a>
</li>
</ul>
</div>
</nav>
This is what my code looks like but it won't color the background green only for the first milisecond or something.
If I inspect the website you can see on the left that it somehow makes it a different color and I don't know why There is nothing in the css making it that color. If I am on the top of the website it makes it transparent and if I scrol this color
In head tag
<link rel="stylesheet" href="/css/bootstrap.css">
<link rel="stylesheet" href="/css/style.css">
Just before the closing of Body Tag
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
Just check if you have added this correctly (or all the files).
You might need to check whether you are trying to change a css of already having !important
And already you are using the class bg-light which color your nav too. Remove it.
<nav class="navbar navbar-expand-md fixed-top sticky-navigation " style="background: green !important;">
<button class="navbar-toggler navbar-toggler-right" type="button" style="background: green !important;" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="ion-grid icon-sm"></span>
</button>
<a class="navbar-brand hero-heading" href="#">Jeroen Hooge</a>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#main">Product <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#features">Werk</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#pricing">Prijs</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#team">Team</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#blog">Blog</a>
</li>
<li class="nav-item mr-3">
<a class="nav-link page-scroll" href="#contact">Contact</a>
</li>
</ul>
</div>
</nav>
I have navigation bar that collapses on windows resize. Besides the usual stuff in nav bar like about, contact...etc, i have two social media links (facebook and twitter). After i resize window, both of the social media items jump to the right of collapsed bar and also show up in the "dropdown" of the collapsed bar.
I would like for the social media items to show on the left of the so called dropdown button and for them to not show up in the collapsed bar.
I've tried this by sourcing them outside of collapsed bar div, but nothing changes.
Any help?
<nav class="navbar navbar-expand-lg navbar fixed-top navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#"><img src="img/logo.png" width="100" height="100" class="d-inline-block align-top" alt=""></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarForCollapse" aria-controls="navbarForCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarForCollapse">
<ul class="navbar-nav ml-auto">
<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="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Our team</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
<div class="navbar-social">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
</li>
<li class="nav-item">
</li>
</ul>
</div>
</div>
</nav>
For visual:
https://jsfiddle.net/8ay2g0tL/3/
Thank you!
RESULT
im not sure if this is the best practice or not, but the way i finally was able to hide it from collapsed navbar is by setting it to display: none
like this:
#media only screen and (max-width: 998px) {
#navbarfbtw{
display:none;
}
}
Just wrap the class="navbar-social" inside the parent class="collapse navbar-collapse", Also there is no reason to use <div class="navbar-social"> so just add social li items (with navbar-social class) in the parent ul element like this:
Updated JsFiddle
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<nav class="navbar navbar-expand-lg navbar fixed-top navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#"><img src="img/logo.png" width="100" height="100" class="d-inline-block align-top" alt=""></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarForCollapse" aria-controls="navbarForCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarForCollapse">
<ul class="navbar-nav ml-auto">
<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="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Our team</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item navbar-social">
</li>
<li class="nav-item navbar-social">
</li>
</ul>
</div>
</div>
</nav>
It's to do with the order in which the elements are rendered on the page.
The collapsed menu is being "un-hidden" and shunting your icons out of place.
Simply put the "navbar-social" div BEFORE the "navbarForCollapse" div.
https://jsfiddle.net/16x8jhu4/9/
<div class="navbar-social">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
</li>
<li class="nav-item">
</li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarForCollapse" aria-controls="navbarForCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarForCollapse">
<ul class="navbar-nav ml-auto">
<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="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Our team</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>