I using bootstrap(4) but the navbar for small viewports doesn't show the hamburger icon. I think the issue could be the asset isn't loading properly, but I can see it being fetched in chrome dev tools-> network.
(website is based on this template
https://wrapbootstrap.com/theme/velocity-for-products-bootstrap-4-WB0N38R04)
Navbar html
<header id="header" class="header navbar-fixed-top">
<div class="container">
<h1 class="logo">
<span class="text">Cheaper</span>
</h1><!--//logo-->
<nav class="main-nav navbar navbar-right navbar-inverse navbar-expand-md" role="navigation">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse">
<span class="navbar-toggler-icon"></span>
</button><!--//nav-toggle-->
<div id="navbar-collapse" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active nav-item"><a class="nav-link" href="{% url 'home' %}">Home</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'how' %}">How it works</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'faq' %}">FAQ</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'about' %}">About us</a></li>
{% if request.user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'users:detail' request.user.username %}">My Profile</a>
</li>
<li class="nav-item nav-item-cta last">
<a class="btn btn-cta btn-cta-secondary" href="{% url 'account_logout' %}">Log out</a>
</li>
{% else %}
<li class="nav-item"><a class="nav-link" href="{% url 'account_login' %}">Log In</a></li>
<li class="nav-item nav-item-cta last"><a class="btn btn-cta btn-cta-secondary"
href="{% url 'users:postcode' %}">Sign Up</a></li>
{% endif %}
</ul><!--//nav-->
</div><!--//navbar-collapse-->
</nav><!--//main-nav-->
</div><!--//container-->
</header><!--//header-->
css class for the icon
.navbar-toggler-icon {
background: transparent url('../images/hamburger-icon.svg') no-repeat center center;
}
You could use some thing like this. I have changed button to a link. And did changes in the .navbar-toggler-icon class as well.
.navbar-toggler-icon {
background: url('https://image.flaticon.com/icons/svg/198/198416.svg')no-repeat center center;
display: inline-block;
height: 17px;
width: 50px;
}
<header id="header" class="header navbar-fixed-top">
<div class="container">
<h1 class="logo">
<span class="text">Cheaper</span>
</h1>
<!--//logo-->
<nav class="" role="navigation">
<a href="" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse">
<span class="navbar-toggler-icon"></span>
</a>
<!--//nav-toggle-->
<div id="navbar-collapse" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active nav-item"><a class="nav-link" href="{% url 'home' %}">Home</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'how' %}">How it works</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'faq' %}">FAQ</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'about' %}">About us</a></li>
{% if request.user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'users:detail' request.user.username %}">My Profile</a>
</li>
<li class="nav-item nav-item-cta last">
<a class="btn btn-cta btn-cta-secondary" href="{% url 'account_logout' %}">Log out</a>
</li>
{% else %}
<li class="nav-item"><a class="nav-link" href="{% url 'account_login' %}">Log In</a></li>
<li class="nav-item nav-item-cta last"><a class="btn btn-cta btn-cta-secondary" href="{% url 'users:postcode' %}">Sign Up</a></li>
{% endif %}
</ul>
<!--//nav-->
</div>
<!--//navbar-collapse-->
</nav>
<!--//main-nav-->
</div>
<!--//container-->
</header>
<!--//header-->
Related
Here is a code for my navbar:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/">BRAND</a>
<div class="navbar-collapse">
<ul class="navbar-nav mr-auto">
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="#">ITEM 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ITEM 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ITEM 3</a>
</li>
{% endif %}
</ul>
<ul class="navbar-nav ml-auto">
{% if user.is_authenticated %}
<li class="nav-item">
<p class="navbar-text">Logged in as:</p>
</li>
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="/login">Login</a>
</li>
{% endif %}
</ul>
</div>
</nav>
And here is my .css file for paddings, and I am guessing that something has to be added here, but I can't figure out what..
#media (min-width: 992px) {
.navbar-nav > .nav-item {
padding-right: 1.5rem;
}
}
#media (min-width: 992px) {
.navbar-brand {
padding-right: 2rem;
}
}
What happens is this:
Wrong alignment
What do I need to do, to get the right side of the navbar to verically align with other items? I have tried to include style="vertical-align:middle to the .css file and to nav-item and nav-link, but it doesn't help.
there is problem with P tag which has text 'Logged in As'.
P tag has margin bottom which is creating problem with alignment.
so you can remove that margin using mb-0 class.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/">BRAND</a>
<div class="navbar-collapse">
<ul class="navbar-nav mr-auto">
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="#">ITEM 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ITEM 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">ITEM 3</a>
</li>
{% endif %}
</ul>
<ul class="navbar-nav ml-auto">
{% if user.is_authenticated %}
<li class="nav-item">
<p class="navbar-text mb-0">Logged in as:</p>
</li>
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="/login">Login</a>
</li>
{% endif %}
</ul>
</div>
</nav>
After several hours of research and variout attempts, I cannot seem to workout how to move this Logout button from within my Navbar to the very right of the screen.
I have tried every example I can find online, creating a new nav bar, setting the float to right, text align to the right, etc.
Please find the attached HTML/Django:
navbar.html:
<nav class="navbar navbar-expand-lg navbar-light bg-light p-0">
<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" style="height: 4rem;">
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'signed in' %}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'add meal' %}">Add Meal</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'view private profile' %}">View Private Profile</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'view food log' %}">Food Log</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'view friends' %}">Friends</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'settings' %}">Settings</a>
</li>
<li class="nav-item" style="float: right">
<a class="nav-link p-3" href="{% url 'logout' %}" style="background-color: #e85c29">Logout</a>
</li>
</ul>
</div>
</nav>
Thank you for your time.
This is because the logout link is enclosed within the div tag in your navbar. Try moving it outside the div block.
<nav style="background-color: green;" class="navbar navbar-expand-lg navbar-light bg-light p-0">
<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" width="100%" id="navbarNav">
<ul class="navbar-nav" style="height: 4rem;">
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'signed in' %}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'add meal' %}">Add Meal</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'view private profile' %}">View Private Profile</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'view food log' %}">Food Log</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'view friends' %}">Friends</a>
</li>
<li class="nav-item">
<a class="nav-link p-3" href="{% url 'settings' %}">Settings</a>
</li>
</ul>
</div>
<a class="nav-item mr-3 nav-link p-3" href="{% url 'logout' %}" style="background-color: #e85c29">Logout</a>
</nav>
change this
<li class="nav-item" style="float: right">
<a class="nav-link p-3" href="{% url 'logout' %}" style="background-color: #e85c29">Logout</a>
</li>
to this
<li class="nav-item" style="float: right; width: 100%;">
<a class="nav-link p-3" href="{% url 'logout' %}" style="background-color: #e85c29">Logout</a>
</li>
I created a navigation Bar using bootstrap in Angular, however I have encountered an issue when adding a user icon as shown in the picture below, that problem does not happen if I instead use a text as shown Below (My Account). How can I fix this and make sure the user icon is centered aligned just like the rest of the links in the navbar?
<nav class="navbar navbar-light navbar-expand-md bg-faded justify-content-center navbar-light bg-light">
<div class="container">
<a href="/" class="navbar-brand d-flex w-50 me-auto">
<img
src="assets/images/myImage.png"
alt="my-image"
loading="lazy"
class="logo"
/>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">Home</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" href="#">Link</a>
</li>
</ul>
<ul class="nav navbar-nav ms-auto w-100 justify-content-end">
<!-- <li class="nav-item">
<a class="nav-link" href="#">Right</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Right</a>
</li>
-->
<li class="nav-item dropdown">
<a class="nav-link" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<img
src="assets/images/user.png"
alt="user-logo"
loading="lazy"
class="logo"
/>
</a>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarScrollingDropdown">
<li><a class="dropdown-item" href="#">Login</a></li>
<li><a class="dropdown-item" href="#">Sign Up</a></li>
<!-- <li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Item</a></li>
-->
</ul>
</li>
</ul>
</div>
</div>
</nav>
Here you go...
The solution that #ethry suggested is not the best one (even though it works). Why using CSS if this can be done with Bootstrap? You just need to add d-flex justify-content-center to the nav-item.
See the snippet below.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<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>
<nav class="navbar navbar-light navbar-expand-md bg-faded justify-content-center navbar-light bg-light">
<div class="container">
<a href="/" class="navbar-brand d-flex w-50 me-auto">
<img src="assets/images/myImage.png" alt="my-image" loading="lazy" class="logo" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active d-flex justify-content-center">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item d-flex justify-content-center">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item d-flex justify-content-center">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item d-flex justify-content-center">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<ul class="nav navbar-nav ms-auto w-100 justify-content-end">
<!-- <li class="nav-item">
<a class="nav-link" href="#">Right</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Right</a>
</li>
-->
<li class="nav-item dropdown d-flex justify-content-center">
<a class="nav-link" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<img src="assets/images/user.png" alt="user-logo" loading="lazy" class="logo" />
</a>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarScrollingDropdown">
<li><a class="dropdown-item" href="#">Login</a></li>
<li><a class="dropdown-item" href="#">Sign Up</a></li>
<!-- <li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item" href="#">Item</a>
</li>
-->
</ul>
</li>
</ul>
</div>
</div>
</nav>
You can use the <center> tag to do this, but I would recommend using CSS instead.
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-light navbar-expand-md bg-faded justify-content-center navbar-light bg-light">
<div class="container">
<a href="/" class="navbar-brand d-flex w-50 me-auto">
<img
src="https://i-need-to-go.to-sleep.xyz/r/hi.png"
alt="my-image"
loading="lazy"
class="logo"
/>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">Home</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" href="#">Link</a>
</li>
</ul>
<ul class="nav navbar-nav ms-auto w-100 justify-content-end">
<!-- <li class="nav-item">
<a class="nav-link" href="#">Right</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Right</a>
</li>
-->
<li class="nav-item dropdown">
<a class="nav-link" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<div style="text-align: center;"><img
src="https://i-need-to-go.to-sleep.xyz/r/hi.png"
alt="user-logo"
loading="lazy"
class="logo"
style="border: 1px solid lime; /*remove*/"
/></div>
</a>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarScrollingDropdown">
<li><a class="dropdown-item" href="#">Login</a></li>
<li><a class="dropdown-item" href="#">Sign Up</a></li>
<!-- <li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Item</a></li>
-->
</ul>
</li>
</ul>
</div>
</div>
</nav>
The center tag has been deprecated, and is not supported by some browsers, so you should probably use the CSS option above instead of <center>.
You can also remove that green border, I just put it there to show that it was actually centered.
this is my code:
<div class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
App
App
<nav >
{% if user.is_authenticated %}
<a class="nav-link" href="#">Link 1</a>
<ul class="navbar-nav">
<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">
{{ user.username }}</a>
<div class="dropdown-menu dropdown-menu-right text-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{% url 'listingfournisseur' %}">Update fournisseur list</a>
<a class="dropdown-item" href="{% url 'updatepayables' %}">Eletronic Payment</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{% url 'listingclient' %}">Update Clients list</a>
<a class="dropdown-item" href="{% url 'account_logout' %}">Log Out</a>
</div>
</li>
</ul>
{% else %}
<a class="p-2 text-dark" href="{% url 'account_login' %}">Log In</a>
<a class="btn btn-outline-primary" href="{% url 'account_signup' %}">Sign Up</a>
{% endif %}
</nav>
</div>
I m tring to have link1 item just on the left of dropdown.
I don t understand why it is up to dropdown ?
this is what I see:
thanks for help
In you nav add the CSS property display: flex and you will have it one next to the other. But after you will just have to play with the size because an tag don't have "padding" but tag have top, left and bottom "padding".
<nav class="b">
<div>ets</div>
<div><ul>test</ul></div>
</nav>
<style>
.b{
display:flex;
}
</style>
Tried to find the solution for RWD to header section using boostrap but not working for ipad and phone.I want to show logo and menu and nav cart for responsive.How to achive to get the solution.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<nav class="navbar navbar-dark bg-dark mb-5">
<a class="navbar-brand" href="#" routerLink='/products'><img width="50" height="50" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcROSGhNugPi-wkkvEePwHNppt8AaZRlUk-y9yEapagLNUaXxy_G" class="logo mr-2" /></a>
<div class="navbar-expand mr-auto">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" routerLink='/home'>Home</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink='/service'>Service</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink='/about'>About</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink='/contact'>Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink='/test1'>test1</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink='/test2'>test2</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink='/test3'>test3</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink='/test4'>test4</a>
</li>
</ul>
</div>
<div class="navbar-expand ml-auto navbar-nav">
<div class="navbar-nav">
<a class="nav-item nav-link" href="https://github.com/beeman" target="_blank">
<i class="fa fa-github"></i>
</a>
<a class="nav-item nav-link" href="https://twitter.com/beeman_nl" target="_blank">
<i class="fa fa-twitter"></i>
</a>
<a class="nav-item nav-link" href="https://medium.com/#beeman" target="_blank">
<i class="fa fa-medium"></i>
</a>
</div>
</div>
</nav>
Demo:https://stackblitz.com/edit/tutorial-angular-cli-v6-styling-bootstrap-ywyjmv?file=src/app/ui/header/header.component.html