Bootstrap 3 Collapsible Menu is not Animating Slide in/out - css

I'm trying to get a navbar fixed at the top of my page to animate (slide in/out) when it appears and reappears. I'd also like it to collapse when viewed on mobile devices.
I'm just starting with bootstrap and most of the code is from a tutorial, including the button which appears when the screen and displays a drop down.
When I call collapse('toggle') there isn't any animation, even though to docs seem to suggest there is supposed to be an animation (http://getbootstrap.com/javascript/#collapse talks about the time between when it starts hiding and is hidden)
I'm using flat ui, though removing it doesn't solve the problem. I also tried removing everything in the button besides the navbar-brand link; it still doesn't animate. I tried seeing if the panel-collapse or navbar-collapse classes would make it animate, also didn't work.
Is there a quick fix to this problem? Should I manually be coding this animation?
Here's the html/js code I'm using:
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(document).click(function() {
$("#lyla-nav").collapse('toggle')
});
});
</script>
<div id="lyla-nav" class="navbar navbar-default navbar-fixed-top collapse nav-collapse">
<div class="container">
<button data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle">
<!--literally is making each line inside of the button--><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>Welcome
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</div>
</div>
</div>
Thank you in advance!

Related

Nested Bootstrap Sidebar item throwing the toys out

With thanks to trevorp the basic side nav bar works perfectly. Then I needed to nest some menu items. This seems logical to me
<li class="collapsed active">
<div class="accordion-group">
<a data-toggle="collapse" data-target="#20"><i class="dropdown-toggle"></i>Accounting <span class="caret"></span></a>
<ul class="sub-menu collapse" id="20">
<li class="collapsed active">
<div class="accordion-group">
<a data-toggle="collapse" data-target="#21"><i class="dropdown-toggle"></i>Income <span class="caret"></span></a>
<ul class="sub-menu collapse" id="21">
<li>Customers</li>
</ul>
</div>
</li>
<li>Purchases</li>
<li>General Ledger</li>
<li>Banks</li>
<li>Invoicing</li>
<li>Financials</li>
<li>Utilities</li>
<li>Reports</li>
</ul>
</div>
</li>
But it produced this result
That just closes when clicked, instead of opening the li item... It's probably something very basic, but the art of staring at it hasn't produced any results yet :-)
I suspect clicking on the sub menu item is closing the parent, but no idea how to overcome that. No idea why the formatting is totally different either!
Thank you
======================= UPDATE =======================
If the second accordion-group div is removed it takes care for the blank menu item, and disabling the script
<script>
/* ensure any open panels are closed before showing selected */
$('.accordion-group').on('show.bs.collapse', function () {
$('.accordion-group .in').collapse('hide');
});
that closes the main menu items when another is opened now gives this result..
That now leaves two questions
How can I select a sub menu item without closing the accordion group?
How can I format the sub menu items in the same colour as the others (white not orange)?
Finally managed to find a way to solve question one
If there is a less verbose method I'd love to hear :-)
Add an onlick method to the sub-menu item
<li class="collapsed active">
<a onclick="holdCollapse();" data-toggle="collapse" data-target="#Menu_21" class="dropdown-toggle collapsed"><i class="fa fa-gift fa-lg"></i>Income </a>
<ul class="sub-menu collapse" id="Menu_21">
<li>Customers</li>
</ul>
</li>
and add a hidden field
<input type="hidden" value="0" id="HiddenField" />
add this script
<script>
function holdCollapse(e) {
$('#HiddenField').val('1');
}
and edit the original script
<script>
/* ensure any open panels are closed before showing selected */
$('.accordion-group').on('show.bs.collapse', function () {
var isSubMenu = $('#HiddenField').val();
if (isSubMenu == '0') {
$('.accordion-group .in').collapse('hide');
}
$('#HiddenField').val('0');
});

Collapsible navbar items disappear when using toggler in Bootstrap 4

Using Bootstrap 4 for the first time, and I am trying to do something that was quite easy in Bs3: I want link items in my navbar to collapse to a hamburger menu when screen size is xs.
Now the documentation and another answer sort of touch on this, but I appear to be following the correct classes, and yet when the screen is sized XS, the link items do not collapse - they just disappear.
Here's the JSFiddle with CSS for the full view, but here's what I am doing with my navbar:
<nav class="navbar navbar-full navbar-light" style="background-color: #E4491C; padding: 0px;">
<p id="toptext">Test</p>
</nav>
<nav class="navbar navbar-full navbar-light" style="background-color: #002b52">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="#">TopDog</a>
<div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar">
<ul class="nav navbar-nav">
<li class="nav-item"><a class="pull-sm-right navbar-brand2" href="#">Contact</a></li>
<li class="nav-item"><a class="pull-sm-right navbar-brand2" href="#">About</a></li>
</ul>
</div>
</div>
</nav>
So I am using toggleable class, I am specifying these as link-items; the only difference I can spot is that I am also using a pull-sm-right class, which should bring the links to the right side of the nav. Removing them did not fix the issue.
Question: Why is Bootstrap failing to display these links as a collapsible menu when I resize the page?
Because it's responsive menu. The links hides when it reaches 768 pixels and the navbar-header is only visible as well as Hamburger Menu Icon.
It looks like the Hamburger Menu Icon is missing too, that's because you didn't add it.
Use this code to add it:
<button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2">
☰
Good luck.

Navbar collapse not working on Bootstrap

I cannot get to work the navbar collapse in Bootstrap 3.
My menu collapse nicely when I change screensize, only it won't show the menu when I press the button.
This is my code:
<header class="container">
<div id="menu" class="navbar navbar-default">
<div class="navbar-header">
<button class="btn btn-success navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="glyphicon glyphicon-chevron-down"></span>
</button>
<div id="logo">
<a href='..'><h3>Logo</h3></a>
</div>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="nav active">Home
</li>
<li class="nav">About
</li>
<li class="nav">Contact
</li>
</ul>
</div>
</div>
</header>
Your HTML works fine, so make sure you are referencing the proper scripts and and styles in your markup
Make sure you have the following in your markup:
bootstrap.min.css
font-awesome.min.css
jquery.js
bootstrap.min.js
Fiddle Works Fine
Copy and paste this HTML:
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
<script type="text/javascript" src="//code.jquery.com/jquery-2.0.2.js"></script>
<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
The issue is not in the HTML your code works perfect in this Fiddle
Check this fiddle
make sure you include the responsive css
http://getbootstrap.com/dist/css/bootstrap.css
and the correct JS
http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js
I also suffered from the same problem, and could not find the solution anywhere. Actually bootstrap.min.js needs jquery to work. SO if you put script src=js/bootstrap.min.js before script src=js/jquery.js it will not work.
The Order of inclusion of jquery and bootstrap.min.js is important.

Fixed Bootstrap navbar to top of dynamic width DIV - not full width of page

My problem
I am using Bootstrap 3.0 and need to use a fixed navbar, which will stay at the top of a DIV on the left side and NOT extend all the way 100% of the width of the window (like I usually see Bootstrap's example do). I have some very simple code below, using ASP.NET MVC 4 which will explain the RenderSection areas.
I have included an image which shows what I am trying to do. Currently the navbar is only extending about 75% of the left side container, not the full 100% of that left side container like I want it to.
Like I said above, I want the navbar to be fixed so when you scroll it stays in one spot within that left DIV.
Any tips/hints would be greatly appreciated! Thanks!
I also saw this question (Navbar fixed to top but not full-width) but I do not want to have to dynamically maintain this navbar with a fixed pixel width in media queries. I'd prefer it to fill out the entire left side DIV that contains it.
(http://i.imgur.com/YLzmkHp.jpg)
My code
<div class="container">
<div class="row">
<!--LEFT SIDE-->
<div class="col-md-9">
<div data-spy="affix" data-offset-top="0">
<nav class="navbar navbar-default" role="navigation">
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="active">Link</li>
<li>Link</li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">Dropdown <b class="caret"></b></a>
<ul role="menu" class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form role="search" class="navbar-form navbar-left">
<div class="form-group">
<input type="text" placeholder="Search" class="form-control">
</div>
<button class="btn btn-default" type="submit">Submit</button>
</form>
</div>
</nav>
</div> <!--end data-spy=affix-->
<!--the LeftSide below just contains basic placeholder text in a <p> tag-->
#RenderSection("LeftSide", true)
</div>
<!--RIGHT SIDE-->
<div class="col-md-3">
<!--the RightSide below just contains basic placeholder text in a <p> tag-->
#RenderSection("RightSide", true)
</div>
</div>
</div>
Partially Solved (update)
I was able to solve my main problem that I listed above by using this bit of jQuery
$(window).resize(function () {
var w = $("#leftSide").width();
$("#navWrapper").css("width", w);
});
But this does not work within an iFrame.
If anyone has any insights on solving this for use in an iFrame, it'd be greatly appreciated.
Have you tried placing your navbar and main content area in one column and then your right sidebar in a column by itself? Then add a bit of CSS to correct for the navbar position and adjust for responsiveness.
LINK: http://www.bootply.com/ZJCGxiUD6g

CSS tabs not working with anchors on bootstrap?

Attempt 1
<div class="bs-docs-example">
<ul class="nav nav-tabs">
<li class="active">Homeaaa</li>
<li>Profilefff</li>
<li>Messagesbbb</li>
</ul>
</div>
JSfiddle
I have also tried setting a data-toggle attribute to "tab", but that only allowed me to click between tabs, it didn't separate the aaa/fff/bbb into different tabs.
This should be possible to be done without any JavaScript.
Attempt 2
The closest I've gotten to a working one is:
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active">
Stir
</li>
<li>
Drink
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="ter">fff</div>
<div class="tab-pane" id="gin">ggg</div>
</div>
</div>
JSfiddle
But this didn't change the URL of the viewer to /#ter or /#gin on click. Also it doesn't seem to work normally in the fiddle...
Your jsFiddle works as expected -- anchor links take you to #gin and #ter. On the other hand, I believe you need to use some JavaScript to actually change the active tab. Here's a try that uses a bit of jQuery:
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active">
Stir
</li>
<li>
Drink
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="ter">fff</div>
<div class="tab-pane" id="gin">ggg</div>
</div>
</div>
JavaScript:
$(document).ready(function() {
$(".nav-tabs li a").click(function() {
var li = $(this).parent("li");
var wch = this.getAttribute("href");
$(li).addClass("active"); //make current li active
$(li).siblings("li").removeClass("active"); //make others inactive
$(".tab-content div").removeClass("active"); //make all tabs inactive first
$(wch).addClass("active"); //activate our tab;
return false; //don't change URL
});
});
And a little demo: little link. Note that the use of jQuery isn't needed; you can easily convert to vanilla JavaScript if you want to avoid using it.
Hope that helped!

Resources