<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<span class="navspacing"></span>
<a class="navitems hover" href="{% url 'home' %}">Home</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNavbar">
<span style="margin:5px;" class="navbar-toggler-icon"></span>
</button>
<div class=" collapse navbar-collapse topnav" id="collapsibleNavbar">
<ul class="navbar-nav" >
{% if user.is_authenticated %}
<li class="nav-item navitems">
<a class="nav-link hovering" href="{% url 'light_novel:characters_page' %}">Characters</a>
</li>
<li class="nav-item navitems">
<a class="nav-link " href="{% url 'light_novel:moves_page' %}">Moves</a>
</li>
<li class="nav-item navitems">
<a class="nav-link" href="{% url 'light_novel:chapters_page' %}">Chapters</a>
</li>
<li class="nav-item navitems">
<a class="nav-link" href="{% url 'light_novel:outfits_page' %}">Outfits</a>
</li>
<li class="nav-item navitems">
<a class="nav-link" href="{% url 'light_novel:sights_page' %}">Sight</a>
</li>
<li class="nav-item navitems">
<a class="nav-link" href="{% url 'light_novel:timelines_page' %}">Timeline</a>
</li>
<li class="nav-item navitems">
<a class="nav-link" href="{% url 'light_novel:scratchpads_page' %}">Scratchpad</a>
</li>
<li class="nav-item navitems">
<a class="nav-link" href="{% url 'light_novel:statistics' %}">Statistics</a>
</li>
<li class="nav-item navitems">
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
</li>
{% else %}
<li class="nav-item navitems">
<a class="nav-link" href="{% url 'login' %}">Login</a>
</li>
{% endif %}
</ul>
</div>
</div>
</nav>
<!-- Option 1: Bootstrap Bundle with Popper -->
<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>
Related
Here's the navbar
<nav class="navbar navbar-expand-md navbar-dark bg-dark static-top">
<button class="navbar-toggler" type="button" data-toggle="collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">item1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">item2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">item3</a>
</li>
{% if request.user.is_authenticated %}
{% if request.user.is_superuser %}
<li class="nav-item">
<a class="nav-link" href={% url 'admin:index' %}>Admin</a>
</li>
{% endif %}
<img src="https://mdbcdn.b-cdn.net/img/new/avatars/2.webp"
class="rounded-circle" style="width: 40px; margin-right: auto"
alt="Avatar"/>
{% else %}
<li class="nav-item">
<a class="nav-link" href={% url 'signin' %}>Sign in</a>
</li>
<li class="nav-item">
<a class="nav-link" href={% url 'signup' %}>Sign up</a>
</li>
{% endif %}
</ul>
</div>
</nav>
Here's how it looks
I need the avatar aligned to the right. So far I tried:
style="width: 40px; display: flex; flex-direction: row-reverse"
and
style="width: 40px; align-self: stretch"
and
style="width: 40px; horiz-align: right"
and
style="width: 40px; display: -ms-inline-flexbox"
and
style="width: 40px; margin-right:10px;"
and the list goes on ... Nothing works.
more details more details more details more details
When using bootstrap I usually drop a spacer element and give it a flex-grow of 1 to push everything to the left and right as follows:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<nav class="navbar navbar-expand-md navbar-dark bg-dark static-top">
<button class="navbar-toggler" type="button" data-toggle="collapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse">
<ul class="navbar-nav w-100">
<li class="nav-item">
<a class="nav-link" href="#">item1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">item2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">item3</a>
</li>
<!-- inserted sneaky spacer below -->
<li class='flex-grow-1'></li>
<img src="https://placekitten.com/40/40" class="rounded-circle" style="width: 40px;" alt="Avatar" />
<li class="nav-item">
<a class="nav-link" href={% url 'signin' %}>Sign in</a>
</li>
<li class="nav-item">
<a class="nav-link" href={% url 'signup' %}>Sign up</a>
</li>
</ul>
</div>
</nav>
I have this bootsrap navBar, when i resize the window the navbar is shrunk and displays the hamburger, however when i click the hamburger the links aren't shown.
this is the code:
<div class="fixed-top">
<nav class="navbar navbar-dark navbar-expand-lg cusSticky" style="background-color: #000000b3;">
<!-- Navbar content -->
<div class="container-fluid">
<a class="navbar-brand" href="{% url 'front:index' %}"><img class="image-responsive"
src="{% static 'front/images/logo2.png' %}"
alt="404"
style="position: relative; max-width: 268px; margin-left:100px;"></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar"
aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0"
style="display: flex; margin-right: 50; margin-left:500px; text: white;">
<li class="nav-item active">
<a class="nav-link" href="{% url 'front:index' %}">Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'front:about' %}">About</a>
</li>
<li class="nav-item active">
<a class="nav-link"
href="{% url 'front:portfolio' %}">Portfolio</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'front:contact' %}">Contact</a>
</li>
<li class="nav-item active">
<a class="nav-link"
href="{% url 'front:calendar' %}">Calendar</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'user_area:loading'%}">
<i class="fa fa-user" aria-hidden="true"></i>
{% if user.is_authenticated %}
User Area - {{ user.first_name}}
{% else %}
Login
{% endif %}</a></li>
</ul>
</div>
</div>
</nav>
</div>
I feel like i am missing something but i can't figure it out.
Instead of data-bs-toggle and data-bs-target use data-toggle and data-target.I solved your problem with the toggler, the rest is up to you... Work on your code! It leaves a lot to be desired ... ;-) Good Luck !
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<title>Bootstrap 4.6 Navbar with toggler</title>
</head>
<body>
<div class="fixed-top">
<nav class="navbar navbar-dark navbar-expand-lg cusSticky" style="background-color: #000000b3;">
<!-- Navbar content -->
<div class="container-fluid">
<a class="navbar-brand" href="{% url 'front:index' %}"><img class="image-responsive" src="{% static 'front/images/logo2.png' %}" alt="404" style="position: relative; max-width: 268px; margin-left:100px;"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0" style="display: flex; margin-right: 50; margin-left:500px; text: white;">
<li class="nav-item active">
<a class="nav-link" href="{% url 'front:index' %}">Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'front:about' %}">About</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'front:portfolio' %}">Portfolio</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'front:contact' %}">Contact</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'front:calendar' %}">Calendar</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'user_area:loading'%}">
<i class="fa fa-user" aria-hidden="true"></i> {% if user.is_authenticated %} User Area - {{ user.first_name}} {% else %} Login {% endif %}</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<script src="https://cdn.jsdelivr.net/npm/jquery#3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
</body>
</html>
It doesn't look as though you have any dropdown-menu's inside the main navbar-nav list. Copy this for as many dropdown's as you need.
<ul class="navbar-nav">
<!-- Dropdown Start -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="servicesDropdown" role="button"
data-toggle="dropdown" aria-expanded="false">
MAIN DROPDOWN BUTTON
</a>
<ul class="dropdown-menu" aria-labelledby="servicesDropdown">
<li><a class="dropdown-item" href="#">DROPDOWN ITEM 1</a></li>
<li><a class="dropdown-item" href="#">DROPDOWN ITEM 2</a></li>
<li><a class="dropdown-item" href="#">DROPDOWN ITEM 3</a></li>
<li><a class="dropdown-item" href="#">DROPDOWN ITEM 4</a></li>
</ul>
</li>
<!-- Dropdown End -->
</ul>
I have developed a django app but for some reason the bootstrap navbar won't show menu items on mobile phone
Whenever I run my app on a mobile device's web browser the hamburger menu does not extend to show my nav items...it is very odd.
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#"><img src="{% static 'images/logo.png' %}"></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">
{% if user.is_authenticated %}
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'dashboard:transactions' %}">Transactions</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'dashboard:quote' %}">Quote Tool</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'dashboard:tracking' %}">My Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'dashboard:home' %}">Home</a>
</li>
<a class="nav-link" href="{% url 'dashboard:support' %}">Support</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
</li>
</li>
</ul>
{% else %}
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'register' %}">Sign up</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'login' %}">Login</a>
</li>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'dashboard:home' %}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'dashboard:quote' %}">Quote Tool</a>
</li>
</ul>
</div>
{% endif %}
</div>
</nav>
Your code works fine in my Django/Bootstrap-project. You should double check that you have imported the Bootstrap JS correctly, as this is probably the reason why the hamburger won't expand. Try using the starter template https://getbootstrap.com/docs/4.3/getting-started/introduction/ and see if it does the trick :)
As suggested by Patrick, I reloaded afresh js from the boot strap starter template hamburger menu started working on mobile.
Patrick: Ans> "You should double check that you have imported the Bootstrap JS correctly, as this is probably the reason why the hamburger won't expand. Try using the starter template https://getbootstrap.com/docs/4.3/getting-started/introduction/ and see if it does the trick :)"
I have an app where I want to use a sidebar containing the main URLs and the brand name with a navbar for some other pages like the FAQ and about us.
However, I'm facing a problem in making the positioning of the sidebar absolute. When I was searching I saw this answer of making the bars to prevent them from overlapping.
As you can see the problem is with the sidebar.
Here's the HTML:
<div class="row">
<div class="col-md-2 bg-dark">
<!-- sidebar -->
<nav class="navbar navbar-light bg-dark" id="sidebar">
<ul class="navbar-nav mr-auto">
<div class="brand-panel">
<li class="nav-item active">
<a class="navbar-brand" href="{% url 'home' %}"><h5>Sentizer <small class="one" > Beta</small></h5></a>
</li>
</div>
<li class="nav-item active">
<a class="nav-link" href="{% url 'patients:dashboard' %}">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'patients:patients_list' %}">Patients</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'accounts:tickets' %}">Tickets</a>
</li>
<li class="nav-item">
<button type ="button" class="button1 nav-link" data-toggle="modal" data-target="#modalContactForm">Feedback</button>
</li>
</ul>
</nav>
</div><!-- sidebar -->
<div class="col-md-10">
<div class="row">
<div class="col-md-12 px-0">
<!-- navbar -->
<nav class="navbar navbar-expand-md navbar-light bg-light sticky-top" id="top-nav1" >
<div class="container-fluid">
<form class="form-inline" action="{% url 'patients:patient_search' %}" method="GET" >
<input class="form-control mr-sm-2" id="sebar" type="text" size="45%" placeholder="Search" aria-label="Search" name="q">
<button class="btn btn-outline-primary btn-sm" type="submit" ><i class="material-icons">search</i></button>
</form>
<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">
<a class="nav-link" href="{% url 'about' %}">About us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'faq' %}">FAQ</a>
</li>
<li class="nav-item">
</li>
{% if user.is_authenticated %}
<li class="nav-item dropdown">
{{request.user.first_name}} {{request.user.last_name}}<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dropdown-item">
<a class="nav-link" href=" {% url 'accounts:details' pk=request.user.pk %}">Profile</a>
</li>
<li class="dropdown-item text-nowrap">
<a class="nav-link" href="{% url 'accounts:logout' %}">Sign out</a>
</li>
</ul>
</li>
<li class="nav-item">
<i class="fa fa-search fa-lg"></i>
</li>
{% else %}
<li class="nav-item text-nowrap">
<a class="nav-link trigger-btn" href="#loginModal" data-toggle="modal">Login</a>
</li>
{% endif %}
</ul>
</div>
</div>
</nav>
</div><!-- navbar -->
</div>
I tried changing the positioning of <nav class="navbar navbar-light bg-dark" id="sidebar"> but it didn't work as it's relying on the background div before it.
How can I fix this and is there a better approach to make to bars in the page without any overlapping issues?
You will need to extend your 'app container' (here your first div#app) to screen height using height: 100vh. Please try it on full page :
#app {
height: 100vh;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<div id="app" class="row">
<div class="col-md-2 bg-dark">
<!-- sidebar -->
<nav class="navbar navbar-light bg-dark" id="sidebar">
<ul class="navbar-nav mr-auto">
<div class="brand-panel">
<li class="nav-item active">
<a class="navbar-brand" href="{% url 'home' %}">
<h5>Sentizer <small class="one"> Beta</small></h5>
</a>
</li>
</div>
<li class="nav-item active">
<a class="nav-link" href="{% url 'patients:dashboard' %}">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'patients:patients_list' %}">Patients</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'accounts:tickets' %}">Tickets</a>
</li>
<li class="nav-item">
<button type="button" class="button1 nav-link" data-toggle="modal" data-target="#modalContactForm">Feedback</button>
</li>
</ul>
</nav>
</div><!-- sidebar -->
<div class="col-md-10">
<div class="row">
<div class="col-md-12 px-0">
<!-- navbar -->
<nav class="navbar navbar-expand-md navbar-light bg-light sticky-top" id="top-nav1">
<div class="container-fluid">
<form class="form-inline" action="{% url 'patients:patient_search' %}" method="GET">
<input class="form-control mr-sm-2" id="sebar" type="text" size="45%" placeholder="Search" aria-label="Search" name="q">
<button class="btn btn-outline-primary btn-sm" type="submit"><i class="material-icons">search</i></button>
</form>
<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">
<a class="nav-link" href="{% url 'about' %}">About us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'faq' %}">FAQ</a>
</li>
<li class="nav-item">
</li>
{% if user.is_authenticated %}
<li class="nav-item dropdown">
{{request.user.first_name}} {{request.user.last_name}}<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dropdown-item">
<a class="nav-link" href=" {% url 'accounts:details' pk=request.user.pk %}">Profile</a>
</li>
<li class="dropdown-item text-nowrap">
<a class="nav-link" href="{% url 'accounts:logout' %}">Sign out</a>
</li>
</ul>
</li>
<li class="nav-item">
<i class="fa fa-search fa-lg"></i>
</li>
{% else %}
<li class="nav-item text-nowrap">
<a class="nav-link trigger-btn" href="#loginModal" data-toggle="modal">Login</a>
</li>
{% endif %}
</ul>
</div>
</div>
</nav>
</div><!-- navbar -->
</div>
I'm trying to implement a bootstrap dropdown menu, despite the right class being applied to the sublist, I'm losing my formatting and the padding that normally applies to bootstrap.
I'm using bootstrap 4.0.0-alpha.2 as follows:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
<nav class="navbar navbar-fixed-top navbar-light bg-faded">
<button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2">
☰
</button>
<div class="collapse navbar-toggleable-xs navbar-collapse" id="exCollapsingNavbar2">
<a class="navbar-brand" href="{% url 'home' %}"><img width="140" src="{% static 'images/openopps_logo.png' %}"</a>
<ul class="nav navbar-nav">
<li class="nav-item oo-roboto-override"><a class="nav-link" href="{% url 'pricing' %}">Pricing</a></li>
<li class="nav-item oo-roboto-override"><a class="nav-link" href="{% url 'home' %}">Blog</a></li>
<li class="nav-item oo-roboto-override dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" href="{% url 'about' %}">
About
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Vision</li>
<li>Our company</li>
<li>FAQs</li>
<li>Contact us</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav pull-xs-right">
{% if user.is_authenticated %}
<li class="nav-item oo-roboto-override"><a class="nav-link" href="{% url 'auth_logout' %}"><button class="btn btn-sm btn-oo-outline">Logout</button></a></li>
{% else %}
<li class="nav-item oo-roboto-override"><a class="nav-link" href="{% url 'registration_register' %}"><button class="btn btn-sm btn-oo">Sign Up</button></a></li>
<li class="nav-item oo-roboto-override"><a class="nav-link" href="{% url 'auth_login' %}"><button class="btn btn-sm btn-oo-outline">Login</button></a></li>
{% endif %}
</ul>
</div>
</nav>
Bootstrap 4 has an extra class required for dropdown menus. Using the following class in the <li> tags works.
<li class="dropdown-item">Vision</li>