Bootstrap clearfix only on mobile? - html

This is the code I have for the navbar, which works great on desktop.
<nav class="navbar navbar-inverse navbar-fixed-top" style="border-bottom-width: 2px;">
<div class="container-fluid">
<div clss="navbar-header">
Logo
<button type="button" class="navbar-toggle" style="border-color: #4c4c4c;" data-toggle="collapse" data-target="#mainNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="mainNavBar">
<div>
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Page 1</li>
<li>Page 2</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</div>
</nav>
But my problem is that in mobile, when extended it looks weird:
Now I can add a clearfix div just before the navbar-collapse and that works great in mobile, but not on desktop. Here are mobile and desktop versions with clearfix div:
Desktop with clearfix:
Desktop without clearfix (i.e. how it should be)
Is there a way I can use clearfix only when in mobile or is there a better way of doing it?

You can use one of the responsive utility classes...
<div class="clearfix visible-xs"></div>
http://www.codeply.com/go/T5V1jGonDY

You have coded wrong nav structure that is why this problem arises.
Kindly Remove the div tag inside this mainNavBar div.
See this example: https://getbootstrap.com/examples/navbar-fixed-top/
Make changes in your code as below:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mainNavBar" 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="mainNavBar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Page 1</li>
<li>Page 2</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
Follow the proper structure of bootstrap no problem will arise.
Hope this will help you. Let me know if there will be any problem?

Related

How to adjust nav bar in small screen?

I am making a navbar in my page using bootstrap 3,it isn't working well with small screen,the nav bar didn't collapse well when i try to minimize the screen,what is the problem?Here is a jsFiddle
<div class="container">
<div class="row">
<img id="logo" src="../lib/css/images/Logo.jpg" class="pull-left" width="100px" height="100px">
<nav class="navbar navbar-inverse" style="height: 40px;margin-left: 105px;">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar" aria-expanded="false">
<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" style="height: 30px;margin-top:-12px;">Welcome</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="dropdown">Add New Category</li>
<li class="dropdown">Search Orders</li>
<li class="dropdown">Calendar</li>
<li class="dropdown">Order status</li>
</ul>
<ul>
<li class="nav navbar-nav navbar-right">
<?php
if(isset($_SESSION["username"]))
{
echo 'Log out';
echo '<h5>Welcome- '.$_SESSION["username"].'</h5>';
}
else
{
header("location:../login.php");
}
include_once "connect.php";
?>
</li>
</ul>
</div>
</div>
</nav>
</div>
</div>
The fiddle doesn't include bootstrap.js so the collapse component isn't working. It works fine when both the css and js are included.
http://www.codeply.com/go/VKrQTeUB4v
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>

Bootstrap hamburger menu isn't working on phone

I have tried to find the issue, but nothing works for me.
If I am resizing the browser the hamburger menu wil pop up and work, but when I take a look on my phone it doesn't work.
Did I really do something wrong?
The code I am using:
HTML:
<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="#">Roy van Eerden</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>Portfolio</li>
<li>Over</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
You can see it live at: www.royvaneerden.com/
Screenshot of the phone example:
Just Place jquery.js above bootstrap.min.js
also, add meta in head
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
Check here
just add this meta tag in head
<meta name="viewport" content="width=device-width, initial-scale=1.0">
You are missing the whole html part, please replace what you have with the nav from here(w3school Documentation).
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Page 1-1</li>
<li>Page 1-2</li>
<li>Page 1-3</li>
</ul>
</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
or by checking the link Collapse Menu Bootstrap

Bootstrap 3 Collapsing navbar color after click

I wish to change the default color styles of the collapsing navbar after being clicked. I successeded styling it before it is collapsed but can't find how to change the colors afterward.
Exmaple from W3Schools:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>

Bootstrap shows only mobile menu

For some reason when i try to implant the 'navbar' with Bootstrap it shows me it in mobile mode no matter what.
And i cant make it to look like it should on desktop mode. i disabled all other stylesheets besides Bootstrap and still stays the same. so it's not some of my CSS that make this happen.
and the code is raw code from getbootstrap.com.
what can be the problem?
We can't figure out what you are missing. However I think you might missing some class.Just Guess.
Navigation Button code:-
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#yourtarget">
EXAMPLE OF Bootstrap Menu(Collapsing The Navigation Bar)
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>

Bootstrap Navbar non collapse (prevent)

I'm trying to make a navbar using bootstrap to my own needs, but have stumbled upon a problem.
I want the first two links from the left (home and menu glyphicons) to not collapse when window is sized down. The rest would collapse.
Screenshot link
enter link description here
Here is my code
<template name="header">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navigation">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<ul class="nav navbar-nav">
<li><a class="navbar-nav" href="{{pathFor 'home'}}"><span class="glyphicon glyphicon-home"></span></a></li>
<li><a class="navbar-nav" id="showMenu" href="#"><span class="glyphicon glyphicon-align-left"></span></a></li>
</ul>
</div>
<div class="collapse navbar-collapse" id="navigation">
<ul class="nav navbar-nav">
<li class="{{activeRouteClass 'home' 'newPosts'}}">
New
</li>
<li class="{{activeRouteClass 'bestPosts'}}">
Best
</li>
{{#if currentUser}}
<li class="{{activeRouteClass 'postSubmit'}}">
Submit Post
</li>
<li class="dropdown">
{{> notifications}}
</li>
{{/if}}
</ul>
<ul class="nav navbar-nav navbar-right">
{{> loginButtons}}
</ul>
</div>
</div>
</nav>
</template>
Move them into a separate <ul> object without the nav navbar-nav classes in order to disable this behaviour.