Bootstrap navbar hamburger is opening but not closing - html

On a phone sized screen, when I click the hamburger once, the navbar opens fine. When I try to close it, nothing happens - it's stuck. Where have I gone wrong? Here's my html:
<header class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#teams-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://{{base_url}}">My Teams</a>
</div>
<nav class="collapse navbar-collapse" id="teams-navbar-collapse">
<ul class="nav navbar-nav">
{% if user.is_authenticated %}
<li>
<a href="{% url 'profile_page' user.pk %}">
My Profile
</a>
</li>
<li>
Logout
</li>
</ul>
{% else %}
{% block login_button %}{% endblock %}
{% endif %}
</nav>
</div>
</header>

I would say this is actually an issue with jQuery Toggle. Please ensure jquery is set to toggle "collapsed". One of the ways bootstrap works is by adding/removing classes to buttons/divs/html elements to display them based on css. For example. Pretty Select dropdowns work by adding "open" to a specific div before or after the select button. Hense you can use jQuery to toggle that open when it's clicked. I hope this helps.
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#teams-navbar-collapse">
<script type="text/javascript">
$( document ).ready(function() {
$("button.navbar-toggle").click(function(){
$("button.navbar-toggle").toggleClass("collapse");
});
});
</script>

Related

CSS: navbar items on top of each other?

in my page the navbar menu items show on top of each other.
Why?
Codepen:
https://codepen.io/ogonzales/pen/mdeNNLB
Code:
<nav class="navbar navbar-expand-md navbar-light fixed-top" style="height: 70px;" id="top-navbar">
<img src="" alt="Ministerios Elim" width="2%" height="50%"/>
<a class="navbar-brand" href="" style="margin-right: 5%;"><span style="margin-left: 3%;">Ministerios Elim</span></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul>
<li>
Home
</li>
{% for item in navigation.menu_items.all %}
<li>
<a href="{{ item.link }}" class="nav-link" {% if item.open_in_new_tab %} target="_blank" {% endif %}>{{ item.title }}</a>
</li>
{% endfor %}
</ul>
<form class="form-inline ml-auto">
Ingresar
Registro
</form>
</div>
</nav>
This is the default behaviour of items inside an unordered list (ul), which are block elements. You need to make them inline-block if you want them to appear on one line.
For example, try adding this code to your CSS:
#navbarCollapse ul li {
display: inline-block;
}
You will see that the items are no longer all underneath each other.
If the options still don't all appear on one line, you are probably having the problem (at least it looks to me like you would, from your codepen you have provided) that the width of your container is not large enough to fit all the elements in it.
Consider making this wider, or displaying less navigation options if design constraints and screen sizes don't allow any more.
You can add "display: inline-block" to your <li>

Jinja not rendering in HTML file

This is probably some sort of silly misunderstanding, but I'm trying to include some Jinja code in my HTML file, as in this file which I found on github:
{% extends "bootstrap/base.html" %}
{% block title %}
Demo App
{% endblock %}
{% block styles %}
{{super()}}
<link rel="stylesheet" href="{{url_for('.static', filename='starter-
template.css')}}">
{% endblock %}
{% block content %}
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Login</li>
<li>Sign Up</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="starter-template">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</div><!-- /.container -->
{% endblock %}
You'll see that the Jinja code is enclosed in the "{% ... %}." However, when I run this file in my web browser, I get the following:
As you can see at the top of the screenshot, instead of executing the Jinja code, the Jinja is being read as HTML text. How can this be fixed?
Thank you!
the jinja templates are not supposed to be viewed in browsers. flask will generate and serve proper html, generated from your templates, when requested.

Bootstrap Navbar unable to collapse

I would want to click the button in the header to expand the list of links, but it only expands, and unable to hide. What should I do to get it working normally?
Here is my code:
<!-- Navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<!-- This is where the button to collapse the list is -->
<img class="icon" alt="Brand" src="img/icon.ico">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapseBtn" aria-expanded="false" aria-controls="collapseBtn">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- This is the list I expect to collapse when I hit the button -->
<div class="collapse navbar-collapse in" id="collapseBtn">
<ul class="container-fluid nav navbar-nav pull-right">
<li><h4 class="navbar-items">Education</h4></li>
<li><h4 class="navbar-items">Experience</h4></li>
<li><h4 class="navbar-items">Skills</h4></li>
<li><h4 class="navbar-items">Contact Me</h4></li>
</ul>
</div>
</div>
</nav>
You have the class of in in your navbar-collapse causing it to remain open other than that your Code is working fine as you can see in the following fiddle
Fiddle
You will want to remove the class of in From your navbar-collapse and then if you are having trouble getting it to open you more than likely forgot to load jquery.js before loading bootstrap.js. So before your bootstrap javascript file you need to load the jquery javascript library. Bootstrap's javascript works off of jquery so you need to load the jquery library first. So before the bootstrap js script link add this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
then after that load your bootstrap js file
<script src="bootstrap.js"></script>

Bootstrap 3 Navbar not working on mobile

My Bootstrap Navbar isn't working on mobile phone view (when it can't display the links). I can't click the button. After many research on Internet and StackOverflow, I tried out the solution and no one works. These are the solutions that I tried;
Verify the data-target and id. As here Check
Add the <meta name="viewport" content="width=device-width, initial-scale=1.0"> Here Check
Add CSS .dropdown-backdrop { position: static; } On Stack, somewhere
Here is my navbar code;
<nav id="layout-nav" class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">7 Frères</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse" id="navigationbar">
<ul class="nav navbar-nav">
{% for item in staticMenu.menuItems %}
<li class="{% if item.isActive %}active{% endif %}">{{ item.title }}</li>
{% endfor %}
</li>
</ul>
</div>
</div>
</nav>
Thanks!
The issue is that you are not including the Bootstrap Javascript(necessary for using the built-in dropdown menu) on your page. Once you have included that, it should work:
<script tpye="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

href not working not moving page to linked file

i used href to link file used this
`
when user clicks on logo user will be redirected to link but in my case its not working.
Also tried:
can someone help what's wrong in this you can also live demo here http://www.xpoter.in/blog/ just click on logo you can find error
my head tag
<div class="navbar-wrapper">
<div class="container">
<div class="navbar navbar-default navbar-fixed-top" role="navigation" id="top-nav">
<div class="container">
<div class="navbar-header">
<!-- Logo Starts -->
<!-- #Logo Ends -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Nav Starts -->
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right scroll">
<li class="active">Home</li>
<li >About</li>
<li >Partners</li>
<li >Contact</li>
</ul>
</div>
<!-- #Nav Ends -->
</div>
</div>
</div>
</div>
The problem is a piece of jQuery on your page:
jQuery(document).ready(function ($) {
$(".scroll a, .navbar-brand, .gototop").click(function (event) {
event.preventDefault();
$('html,body').animate({scrollTop: $(this.hash).offset().top}, 600, 'swing');
$(".scroll li").removeClass('active');
$(this).parents('li').toggleClass('active');
});
});
Which fires on click of .navbar-brand, and you are using event.preventDefault() which is preventing your link from working