I'm trying to add three icons at the right corner, search, notification bell and user. I do not want to collapse since this is for an Electron desktop application and the navbar needs to be fixed.
<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/search.svg" alt="">
</a></li>
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/bell.svg" alt="">
</a></li>
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/person.svg" alt="">
</a></li>
</ul>
</nav>
In doing so, the icons appear one after another vertically which widens the navbar. How do I correct this? I am relatively new to Bootstrap.
On the ul element change the class to just nav instead of navbar-nav & add class d-flex
<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="nav d-flex">
<li class="nav-item">
<a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/search.svg" alt="" />
</a>
</li>
<li class="nav-item">
<a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/bell.svg" alt="" />
</a>
</li>
<li class="nav-item">
<a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/person.svg" alt="" />
</a>
</li>
</ul>
</nav>
Here's a codesandbox where it's working https://codesandbox.io/s/weathered-wildflower-86fv8
Give display: inline-block to ul and li tag.
ul.navbar-nav, li.nav-item{
display: inline-block;
}
<nav class="navbar navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/search.svg" alt="">
</a></li>
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/bell.svg" alt="">
</a></li>
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/person.svg" alt="">
</a></li>
</ul>
</nav>
There is a Stack Overflow answer that addresses your issue.
Extracting the code from this answer you will be able to custom your navbar properly:
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="navbar-brand" href="#">Navbar</a>
</li>
</ul>
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/search.svg" alt="">
</a></li>
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/bell.svg" alt="">
</a></li>
<li class="nav-item"><a class="nav-link p-2" href="#">
<img src="node_modules/bootstrap-icons/icons/person.svg" alt="">
</a></li>
</ul>
</nav>
The only thing that matter here will be the mr-auto in the first ul.
You'll have more explanation on this page to understand how it works.
Related
I am trying to make a navbar with Bootstrap 4, but my code doesn't seem to work. My code practically mirrors the tutorials, with only a few changes to nav-brand. What did I do wrong? Here is what it looks like.
<nav class="navbar sticky-top navbar-light bg-light">
<a class="navbar-brand" href="/">
<img src="/assets/logo/logo.svg" width="30" height="30" class="d-inline-block align-top"
alt="">
<b class="hojasdeplata">Fourteen Trees</b>
</a>
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
It turns out that I needed to move nav-brand into a div with the rest of the navigation.
I have been trying to get a navbar in Bootstrap 5 working with dead centered links and a left brand logo. However using flexbox options in Bootstrap 5 I can only seem to get the nave links sort of centered in a flex container. However the collapse behavior works as expected.
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top navbar-default">
<div class="container-fluid">
<a href="#" class="navbar-brand me-auto">
<img style="height: 45px" src="https://lanman2018.ieee-lanman.org/files/2016/01/sample-logo#2x.png">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar2">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse justify-content-center" id="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">page link/a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown" aria-expanded="false">dropdown</a>
<ul class="dropdown-menu" aria-labelledby="dropdown">
<li>
<a class="dropdown-item" href="#">2nd Page</a>
</li>
<li>
<a class="dropdown-item" href="#"> This is a really long page nameS</a>
</li>
<li>
<a class="dropdown-item" href="#">still a long name</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">about us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Page</a>
</li>
</ul>
</div>
</div>
</nav>
If I set the logo position to absolute I get mostly what I am looking for but upon collapse the nav button sits under the logo. I am probably missing something obvious as I usually don't do front end.
Here is a link to a jsfiddle where I have both of the solutions I've been working on https://jsfiddle.net/0s24hLmf/
It should work if you push the toggler to the right using ms-auto...
<nav class="navbar navbar-expand-md navbar-dark bg-dark navbar-default">
<div class="container-fluid">
<a href="/index.php" class="navbar-brand nav-logo me-auto position-absolute top-0">
<img style="height: 45px" src="https://lanman2018.ieee-lanman.org/files/2016/01/sample-logo#2x.png">
</a>
<button class="navbar-toggler ms-auto" type="button" data-bs-toggle="collapse" data-bs-target="#navbar2">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse justify-content-center" id="navbar2">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Page Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown2" aria-expanded="false">dropdown</a>
<ul class="dropdown-menu" aria-labelledby="dropdown">
<li><a class="dropdown-item" href="#">2nd Page</a>
</li>
<li><a class="dropdown-item" href="#"> This is a really long page nameS</a></li>
<li><a class="dropdown-item" href="#">still a long name</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">about us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Page</a>
</li>
</ul>
</div>
</div>
</nav>
Demo
I'm trying to get the flag icons in the header closer together (I've attached a picture of the relevant section). I've switched around CSS values, but so far no success. I'm using Bootstrap as well.
Here is the relevant code:
.flag {
height: 25px;
width: 25px;
padding: 0px;
}
<nav class="navbar navbar-expand-sm navbar-light bg-light mb-3">
<div class="container">
<a class="navbar-brand" href="#">
<img src="./images/logo/LOGO DARKGLOBE.png" height="100px" width="150px">
</a>
<ul class="navbar-nav align-items-center">
<li class="nav-item">
<a class="nav-link" href="./home.html">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle active" data-toggle=dropdown href="#">Empresa</a>
<div class="dropdown-menu">
Quem somos
Missao & Valores
Ambiente & Sustentabilidade
Higiene, Seguranc & Saude
Emprego & Igualdade de Oportunidades
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Projectos em Curso</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./contactos.html">Contacto</a>
</li>
<li class="nav-item">
<div class="row">
<div class="col">
<a href="#">
<img class="flag" src="./images/flags/portugal-flag-button-round-icon-256.png">
</a>
</div>
<div class="col">
<a href="#">
<img class="flag" src="./images/flags/spain-flag-button-round-icon-256.png">
</a>
</div>
</div>
<div class="row">
<div class="col">
<a href="#">
<img class="flag" src="./images/flags/france-flag-button-round-icon-256.png">
</a>
</div>
<div class="col">
<a href="#">
<img class="flag" src="./images/flags/united-kingdom-flag-button-round-icon-256.png">
</a>
</div>
</div>
</li>
</ul>
</div>
</nav>
I'm guessing this is a fairly straightforward fix, but this is the first time I'm creating a website from scratch. The little I know about web design I've gleamed from reading here and there. Thanks in advance!
Header
I'm just starting to get to grips with bootstrap.
I'm trying to create a vertical-navbar on the left of the page after the user has scrolled past the full-page 'intro' using bootstrap 4. The code below produces the navbar on the left side of the page, however there is a problem with it
The navbar stays in a collapsed state, even after resizing the window small and large again
Why does the code cause the navbar to start closed?
Thanks, Jeff
<header id="home" class="jumbotron h-100vw w-100vw">
...
</header>
<div class="container-fluid">
<div class="row">
<div class="col-md-2">
<nav class="navbar navbar-expand-md navbar-light">
<a class="navbar-brand" href="#home">
<img src="img/logo.png" class="img-fluid" alt="Home">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#nav-content" aria-controls="nav-content"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse-md flex-column" id="nav-content">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#about"></a>About Me</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#work">My Work</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#connect">Stay Connected</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Get In Touch</a>
</li>
</ul>
</div>
</nav>
</div>
<main class="col-md-10">
REST OF MY CONTENT ON THE RIGHT
</main>
</div>
There is no navbar-collapse-md class. Change it to just navbar-collapse.
<div class="collapse navbar-collapse flex-column" id="nav-content">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#about"></a>About Me
</li>
<li class="nav-item">
<a class="nav-link" href="#work">My Work</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#connect">Stay Connected</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Get In Touch</a>
</li>
</ul>
</div>
When I run this code my image, which is a small picture of myself and my wife is being padded on the right and left side with a thin white line. I can't quite figure out what I'm missing.
Not sure if I'm using the navbar correctly as I'm still trying to figure this stuff out.
<nav class="navbar navbar-expand-sm bg-secondary navbar-dark fixed-top">
<!-- Brand/logo -->
<div class="container col-sm-12">
<a class="navbar-brand" href="#">
<img src="http://dishtruck.com/joe_tn.jpg" alt="logo" <style width ="40px" height = "40px">
</a>
<!-- Links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#portfolio">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Social Media</a>
</ul>
<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</ul>
</div>