Bootstrap toggle button works only once when clicked - html

I'm having problems in the Bootstrap navigation menu. When I freshly reload my page, the toggle button works fine i.e. on click it shows the li items. However, after the first click, it does not work. In my Master page I already have a Navigation Menu of Bootstrap, which is working absolutely fine. The problem is occurring for my child page.
Here is my rendered code for the first time:
<nav class="navbar navbar-default" role="tab">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2" >
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
<ul class="nav navbar-nav" id="tabHeader">
<li>
<a class="dropdown-toggle align-center tabColor" id="divFavItemsTab" data-toggle onclick="ShowFavouriteNew();">
<asp:Literal ID="literalMyFav" runat="server" Text="<%$ Resources:Resource,lblMyFavorites %>"></asp:Literal>
</a>
</li>
<li>
<a class="dropdown-toggle align-center tabColor" id="divMyItemsListTab" datatoggle onclick="ShowMyItemsNew();">
<asp:Literal ID="literalCmpitems" runat="server" Text="<%$ Resources:Resource,lblCompanyItem %>"></asp:Literal>
</a>
</li>
<li>
<a class="dropdown-toggle align-center tabColor" id="divPackageTab" onclick="ShowPackagesNew();">
<asp:Literal ID="ltrlCmpPackages" runat="server" Text="<%$ Resources:Resource,lblPackage %>"></asp:Literal>
</a>
</li>
<li>
<a class="dropdown-toggle align-center tabSelected" id="divOnlineTab" onclick="ShowOnlineNew();">
<asp:Literal ID="ltrlOnline" runat="server" Text="<%$ Resources:Resource,lblOnline %>"></asp:Literal>
</a>
</li>
</ul>
</div>
</div>
</nav>
This is my code when I click on the toggle button:
<nav class="navbar navbar-default" role="tab">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2" >
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse in" id="bs-example-navbar-collapse-2">
<ul class="nav navbar-nav" id="tabHeader">
<li>
<a class="dropdown-toggle align-center tabColor" id="divFavItemsTab" data-toggle onclick="ShowFavouriteNew();">
<asp:Literal ID="literalMyFav" runat="server" Text="<%$ Resources:Resource,lblMyFavorites %>"></asp:Literal>
</a>
</li>
<li>
<a class="dropdown-toggle align-center tabColor" id="divMyItemsListTab" datatoggle onclick="ShowMyItemsNew();">
<asp:Literal ID="literalCmpitems" runat="server" Text="<%$ Resources:Resource,lblCompanyItem %>"></asp:Literal>
</a>
</li>
<li>
<a class="dropdown-toggle align-center tabColor" id="divPackageTab" onclick="ShowPackagesNew();">
<asp:Literal ID="ltrlCmpPackages" runat="server" Text="<%$ Resources:Resource,lblPackage %>"></asp:Literal>
</a>
</li>
<li>
<a class="dropdown-toggle align-center tabSelected" id="divOnlineTab" onclick="ShowOnlineNew();">
<asp:Literal ID="ltrlOnline" runat="server" Text="<%$ Resources:Resource,lblOnline %>"></asp:Literal>
</a>
</li>
</ul>
</div>
</div>
</nav>
Up till now everything works fine, and I can see on click my li items. But this happens only for the first click. If I click again on the button so that these li" items get collapsed, they are not. I found out that in class as you can see above gets appended after first click is not being removed on second click. So what I did was I ran a jQuery like this:
$("#btnBsTab").click(function () {
if ($("#bs-example-navbar-collapse-2").hasClass("in")) {
$("#bs-example-navbar-collapse-2").removeClass("in");
} else {
$("#bs-example-navbar-collapse-2").addClass("in").css({height:'auto !important'});
}
});
});
Here btnBsTab is the button id, and I removed the data-target attribute from the code.
Now this works fine for me but I don't want to do like this way as bootstrap itself offers "data-target" functionality that actually handles div id on every click.
I am using jquery-1.9.0 and bootstrap 3.0.0 css and bootstrap.js also.

Related

How to get hamburger icon to show before overlap in navbar

I added a new menu item to a navbar, but now when resizing smaller, the top Account menu item in yellow(see screenshot)(the div with 'navbar-right-container' in the HTML) moves down into the main navbar. If I resize even smaller, the hamburger icon shows up. I want the hamburger icon to show up before the top menu item overlaps into the other navbar. Below is a snippet of the HTML. I tried adding padding to the body as suggested by other posts but that did not work. How can I get the hamburger icon to show up before it overlaps? Thanks.
<div id="navigation" class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-expand-background">
</div>
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-brand">
</div>
</div>
<div class="navbar-collapse collapse">
<div class="navbar-middle-container">
<ul class="nav navbar-nav navbar-middle">
<li>
<a href="javascript:openModalAction('/Manage/Accounts')" class="navbar-account-switch">
<span>Account:<br />My Account</span> <span class="caret caret-right caret-collapsible"></span>
</a>
</li>
<li class=" nobr">
<a href="/" title="My Dashboard" >
DASHBOARD
</a>
</li>
<li class=" dropdown nobr">
<a href="/Quotes" class="dropdown-toggle" data-toggle="dropdown">
ACCOUNTS
<b class="caret caret-collapsible"></b>
</a>
<div class="dropdown-menu dropdown-menu-multicolumn ">
<div class="dropdown-menu-head"><div class="dropdown-menu-head-border"></div></div>
<table class="table table-condensed">
<tr>
<td>
<ul class="dropdown-menu-col">
<li class="nobr"><div class="dropdown-menu-col-header">MANAGE</div></li>
.......................................<div class="navbar-right-container">
<ul class="nav navbar-nav navbar-right">
<li class=" dropdown nobr">
<a href="/Quotes" title="Manage Account" class="dropdown-toggle" data-toggle="dropdown">
My name
<b class="caret"></b>
</a>
My Navbar
It is hard to presume without a working example. But almost certainly you should add some to your CSS breakpoint. Add 12em or 200px. Or make an entirely new breakpoint to focus specifically on that element.
You could resort to hacky tricks like negative margin width to offset the new element's impact on the layout. This may affect your ability to click and require even more rules.

my bootstrap navbar not working properly

i am new in bootstrap and having some difficulty in navbar (mobile view). i have added a navbar and added a toggle button, but it doesn't seems to be working perfectly. i am following the steps as told in tutorials and examples but still don't get the result right. navbar is toggling but when i click the toggle button, it toggles in and off simultaneously. also the toggle button is visible even on larger screen.
here's my code
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-menu">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div id="navbar-menu" class="collapse navbar-collapse">
<nav id="nav-area">
<ul class="nav-bar-list">
<li>
<a>About</a>
</li>
<li>
<a>Blog</a>
</li>
<li>
<a>Tools</a>
</li>
<li>
<a>Services</a>
</li>
<li class="contact-button">
<a>Contact</a>
</li>
</ul>
</nav>
</div>
please tell me where i am doing it wrong? i am using bootstrap version 4.0
It works fine when I copied your code to this snippet. Are you sure you included the bootstrap js & css files along with jquery in your code? If so, then something else that you haven't posted must be interfering.
You need to add your own css to hide it on a larger screen.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-menu">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div id="navbar-menu" class="collapse navbar-collapse">
<nav id="nav-area">
<ul class="nav-bar-list">
<li>
<a>About</a>
</li>
<li>
<a>Blog</a>
</li>
<li>
<a>Tools</a>
</li>
<li>
<a>Services</a>
</li>
<li class="contact-button">
<a>Contact</a>
</li>
</ul>
</nav>
</div>

Bootstrap collapse not working even though js loaded

I have the following data-toggle i want to collapse for the menu. I have provided the necessary bootstrap classes, but it's still not working either.
Html code:
<div class="navbar navbar-compact">
<div class="navbar-inner">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a rel="nofollow" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse" title="Toggle menu">
<span class="menu-name">Menu</span>
<span class="menu-bars">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</span>
</a>
<!-- Everything you want hidden at 940px or less, place within here -->
<div class="nav-collapse collapse">
<ul class="nav" id="topMenu" data-submenu="horizontal">
<li class=" active ">
<a rel="nofollow" href="//ss-template-blog03.simplesite.com/434337774">FRONT PAGE</a>
</li>
<li class=" ">
<a rel="nofollow" href="//ss-template-blog03.simplesite.com/434337775">BLOG</a>
</li>
<li class=" ">
<a rel="nofollow" href="//ss-template-blog03.simplesite.com/434337777">CONTACT</a>
</li>
</ul>
</div>
</div>
</div>
</div>
My Bootstrap classes that i have loaded into my project
bootstrap.collapse-2.3.2.js
bootstrap.dropdown-2.3.2.js
bootstrap.modal-2.3.2.js
I have my own CSS for the styling
This is how i load my js files
You have 2 copy of Jquery.js files...
remove one of them
And include Bootstrap.js file after Jquery.js file.
Update:
Do not remove dot in ".nav-collapse" as suggested in another answer.
if this does not work.. try removing all other Bootstrap includes
I have Created Jsfidle:
[https://jsfiddle.net/DTcHh/40014/]

Bootstrap 3 navbar not rendering properly in Microsoft Edge

I have a navbar in my project which renders as expected in chrome, FF and IE 11, but somehow Internet Edge is special.
Below is the html code which defines the navbar:
<nav class="navbar navbar-default navbar-static-top" style="margin-bottom: 0px" id="mainNavbar">
<div class="container-fluid">
<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="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="desktop.aspx">
<img id="Image1" style="padding-top:0px; padding-left:0px;width:200px;height:44px;" src="logo.png"/>
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="affected.aspx"><img src="log-incident-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Log an incident</span></a></li>
<li id="adminMenuItem">
<a href="myIncidents.aspx">
<img src="my-incidents-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">My Incidents</span>
</a>
</li>
<li>
<a href="incidentRegister.aspx">
<img src="allocate-incident-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Allocate incident</span>
</a>
</li>
<li>
<a href="dashboard.aspx">
<img src="dashboard-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Dashboard</span>
</a>
</li>
<li>
<a href="admin.aspx">
<img src="settings-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Admin</span>
</a>
</li>
<li>
<a href="default.aspx">
<img src="logout-icon.svg" style="height:25px;"/>
<span style="margin-left:5px;">Log out</span>
</a>
</li>
</ul>
</div>
</div>
</nav>
Below is what the navbar should look like:
And here is what Microsoft Edge spits out:
The link tags seem to be taking up all the space, but I can't figure out a way to make them shrink to the width of the content without breaking the layout further. Any suggestions?
I've just found out that I have the same issue.
When I removed the svg icons, it worked. Try using .png, .jpg or whatever. Must do the same for items with icons inside the menu!
Header file is written to IE compatibility guide. Create a new CSS file, dedicated to deal with Internet explorer browser compatibility problems.

Bootstrap collapsed navbar showing empty

When I click on the hamburger menu in my nicely collapsed bootstrap navbar on my phone, the layout slides to the side as expected, but shows me an empty white (or whatever body background colour I have) bar instead of the navigation. Closer inspection with firebug showed that upon clicking the button, some classes got changed on the navbar-collapsebut it remains tagged as invisible.
I have recompiled Bootstrap from LESS to change the point at which it collapses, but the issue seems persistent even with 'vanilla' bootstrap.
Code:
<nav class="navbar transparent navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header" style="padding-right: 0px; min-width: 50px;">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation-example-2">
<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 hidden-xs hidden-sm" href="index.html"><span class="glyphicon glyphicon-home" style="padding-right: 0px;"></span></a><a class="navbar-brand hidden-lg hidden-md" href="index.html">De Fijnkost</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navigation-example-2">
<ul class="nav navbar-nav navbar-right">
<li>
Fijne Vleeswaren
</li>
<li>
Bereide Gerechten
</li>
<li>
Eigen salades
</li>
<li>
Kazen & Kaasschotels
</li>
<li>
Belegde Broodjes
</li>
<li>
Contact
</li>
<li>
Nieuws
</li>
<li class="dropdown">
<a class="dropdown-toggle btn btn-white btn-fill" data-toggle="dropdown" href="#">Bestel <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
Kaasschotel
</li>
<li class="disabled">
Broodjes
</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid-->
</nav>
Same thing happens on pages without the transparent or navbar-fixed-top class. transparent is added by my CSS. Page is visible on defijnkost.be
Your .navbar-collapse is set to display: none !important as far as I can see.
If you set it to display: block in your mobile view media query it should show up just fine.