Hamburger menu dropdown on the right side - html

I'm trying to position the hamburger menu on the right when I click on it, but I'm not managing to adjust the CSS for that.
I have this HTML code:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
<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>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<div class="navbar-header">
<p class="navbar-text navbar-right">
Username
</p>
</div>
</div>
</nav>
Ad this CSS:
#media (max-width: 1200px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
How to adjust this CSS so that the hamburger menu is on the right when clicking on it? The padding of the boxes must be appropriate to the size of the words inside it. Like this:
It's okay if it overwrites the space under it.
I need a solution that uses this CSS code, only. See more here.
Thanks.

Change collapse.in selector to
.collapse.in{
display:block !important;
position:absolute;
float:right;
right: 0;
}

Related

Bootstrap navigation logo on center

I try to design a centered logo navigation but i have some output problems
.navbar {
background-color: #231f20;
min-height: auto;
position: relative;
top: 0px;
font-size: 13px;
width: auto;
border-bottom: none;
margin-bottom: 0px;
padding: 40px 0px;
}
.navbar-brand {
padding: 0 15px;
height: 96px;
}
#media (min-width: 768px) {
.navbar-nav {
position: relative;
right: -50%;
}
.navbar-nav > li {
position: relative;
left: -50%;
}
.navbar-nav > li a {
line-height: 126px;
vertical-align: middle;
padding: 0 24px;
}
}
#media (min-width: 992px) {
.navbar-nav > li a {
padding: 0 40px;
}
}
#media (min-width: 1200px) {
.navbar-nav > li a {
padding: 0 50px;
}
}
/////
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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>
<a class="navbar-brand hidden-sm hidden-md hidden-lg" href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Who We Are</li>
<li>Our Food</li>
<li class="hidden-xs"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></li>
<li>Book a Table</li>
<li>Promotions</li>
</ul>
</div>
</div>
</nav>
Also, demo at http://codepen.io/anon/pen/egqxjW
What is the problem that is causing that white space?
PS: Is there a better way to get the same result? What should i do to include the logo only once in the source code?
right: -50%; moved the ul 50% to the right of where it should be. Its width stay the same (100% of the container), and it's moved by 50% to the right, so 50% of the ul is outside of the container, bleeding out of screen.
I made some change to achieve the same result you want, using text-align: center and display: inline-block instead. They are marked with /* change */ in the CSS.
#import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
.navbar {
background-color: #231f20;
min-height: auto;
position: relative;
top: 0px;
font-size: 13px;
width: auto;
border-bottom: none;
margin-bottom: 0px;
padding: 40px 0px;
}
.navbar-brand {
padding: 0 15px;
height: 96px;
}
#media (min-width: 768px) {
ul.navbar-nav {
position: relative;
float: none;
/* change */
text-align: center;
/* change */
}
ul.navbar-nav>li {
position: relative;
display: inline-block;
/* change */
vertical-align: middle;
float: none;
}
ul.navbar-nav>li a {
line-height: 126px;
vertical-align: middle;
padding: 0 24px;
}
}
#media (min-width: 992px) {
.navbar-nav>li a {
padding: 0 40px;
}
}
#media (min-width: 1200px) {
.navbar-nav>li a {
padding: 0 50px;
}
}
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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>
<a class="navbar-brand hidden-sm hidden-md hidden-lg" href="#"><img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" /></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Who We Are</li>
<li>Our Food</li>
<li class="hidden-xs">
<img src="http://i.imgur.com/SC9LKtA.png" alt="Brand" width="180" />
</li>
<li>Book a Table</li>
<li>Promotions</li>
</ul>
</div>
</div>
</nav>
You have in your style a rule which is setting right: -50% on the navbar. Unfortunately, since the UL navbar displays as a block you wind up with an element that is 100% moving to the right 50% and winding up offscreen.
Instead of messing with right relative positioning you should try the navbar-right bootstrap class. Like so:
<ul class="nav navbar-nav navbar-right">
Most of the layouts from bootstrap play with floats, so you can't just use relative positioning expecting it to behave the same way.
Lastly you should compare it with the official documentation responsive navbar example here: https://getbootstrap.com/components/#navbar
You can see the resulting example here: http://codepen.io/anon/pen/NdQJRb

Centered brand moving slightly when clicking between navigation links

I'm building a website for somebody free of charge using Bootstrap. I'm a bit of an amateur at code and foolishly decided to use a centered logo in my header navigation, something I've never done before.
The navigation is currently laid out like this.
<nav class="navbar navbar-default">
<div class="nav-border">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data- toggle="collapse" data-target="#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="/"><img src="<?php bloginfo('stylesheet_directory'); ?>/img/logo.png" width="222" class="img-responsive"> </a> </div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-left">
<li>About us</li>
<li>Our service</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Our blog</li>
<li>Contact</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
<!--/.container-fluid -->
</nav>
and here's the CSS
.navbar-brand {
transform: translateX(-50%);
left: 50%;
position: absolute;
}
.navbar {
background: #012d52;
border-radius: 0;
border:none;
font: 22px 'Playfair Display', serif;
text-transform: uppercase;
padding: 10px 0;
}
.nav-border {
border-top: 1px solid #576e81;
border-bottom: 1px solid #576e81;
}
.navbar-default .navbar-nav>li>a {
color: #fff;
text-decoration: none;
}
.navbar-default .navbar-nav>li>a:hover {
color: #acd1f0;
}
.navbar-brand {
padding: 0;
margin:0;
z-index: 20;
}
.navbar-brand>img {
height:auto;
width: 222px;
padding: 7px 14px;
margin-top: -77px
}
.navbar-right {
margin-right: 15%;
}
.navbar-left {
margin-left: 15%;
}
.navbar>.container .navbar-brand, .navbar>.container-fluid .navbar-brand {
margin-left: 0;
}
.navbar-default .navbar-toggle:focus, .navbar-default .navbar-toggle:hover {
background-color: transparent;
}
.navbar-default .navbar-toggle {
border-color: #576e81;
}
.navbar-default .navbar-collapse, .navbar-default .navbar-form {
border-color: #576e81;
}
clicking between the two seperate lists makes the logo in the middle shift slightly and I have no idea why. I've tried altering/playing with the CSS using fixed widths to try and find a solution but I'm completely stumped!
The code is based on something I found on Codepen
Any advice would be greatly appretiated.
Sigh...I've just figured it out.
The two links on the right hand side contain content on their pages which cause the browsers scrollbar to appear, this is reducing the width of the window. The other two links on the left hand side go to pages which do not have any content added yet.
Funny how you always find a solution just after you've asked for help!

NAVBAR Loss of responsiveness in mobile view

I've made my navbar a clearfix and added another ul to the right side of it, now it doesn't work in mobile view mode on Chrome?
When using mobile view the drop down button no longer works, also at some view ports it displays the bar in two lists making the navbar a lot taller?
HTML
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- 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-1">
<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="#">Logo</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>
Tyres
</li>
<li>
Mags
</li>
<li>
Gallery
</li>
<li>
Blog
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
Locate a Store
</li>
<li>
Cart
</li>
<li>
Search
</li>
<li>
Login
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
CSS Code Below
.navbar {
font-size: 14px;
font-weight: 300;
line-height: 1.6;
min-height: 65px;
position: fixed;
}
.navbar-inverse .navbar-brand {
color: #ffffff;
}
.navbar-inverse .navbar-nav>li>a {
color: #ffffff;
float: left;
line-height: 60px;
padding: 0 30px;
text-decoration: none;
}
/* Clearfix the Navbar */
.clearfix:before, .clearfix:after,
.navbar:before, .navbar:after {
content: " "; display: table;
}
.clearfix:after,
.navbar:after {
clear: both;
}
/* Navbar styles */
.navbar-inverse .navbar-nav>li>a:hover {
background-color: #2b2b2b;
color: #ffffff;
}
You forget to add id to div respone to collapse, just add it and the button work fine
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
Remove float: left; in class .navbar-inverse .navbar-nav > li > a and it will work
.navbar-inverse .navbar-nav > li > a {
color: #ffffff;
line-height: 60px;
padding: 0 30px;
text-decoration: none;
}
About two row menu in some viewport, i think you can add this
#media (min-width: 768px) and (max-width: 1000px) {
.container {width: auto}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,.1);
margin: 0 -15px !important;
overflow-x: hidden !important;
}
.navbar-collapse.collapse {
display: none !important;
}
.navbar-collapse.collapse.in {
display: block !important;
}
.navbar-header .collapse, .navbar-toggle {
display:block !important;
}
.navbar-header {
float:none;
}
.navbar-nav > li, .navbar-nav {
float: none !important;
}
.navbar-collapse.in {
overflow-y: visible !important;
overflow-x: hidden !important;
}
}
Demo

Bootstrap 3 Menu Breakpoint change but now menu isnt collapsing

Hey Guys so Im struggling to get this right. This is my code for the menu. I have successfully changed the breakpoint of the menu but now it doesnt collapse untill it hits the original breakpoint.
<nav class="navbar navbar-default" id="navigation-top-affix">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsemenu">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-brand visible-xs-block">Menu</div>
</div>
<div class="collapse navbar-collapse" id="collapsemenu">
<ul class="nav navbar-nav">
<li>Home</li>
<li>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Product Portfolio
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Allied products and commodities</li>
<li>Artisan and speciality bread mixes</li>
<li>Breads</li>
<li>Catering products</li>
<li>Chocolate products</li>
<li>Confectionery premixes</li>
<li>Dairy products and imitation creams</li>
<li>Decorative products</li>
<li>Equipment, hardware and smalls</li>
<li>Essences and colours</li>
<li>Fruit pie fullings and toppings</li>
<li>Functional ingredients</li>
<li>Leavening agents</li>
<li>Paper products, foils and packaging</li>
<li>Rolls premixes</li>
</ul>
</li>
<li>Yeast</li>
<li>Tools</li>
<li>Principals</li>
<li>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Forms
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Credit Application Form</li>
<li>Customer Request Form</li>
</ul>
</li>
<li>News</li>
<li>Product COAs</li>
<li class="last">Contact Us</li>
</ul>
</div>
</nav>
Ive made the breakpoint 1200px since the menu is so long. Here is the css ive used to overide the original breakpoint.
#media (max-width: 1200px) {
.navbar-header {
float: none !important;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block !important;
}
.navbar-collapse {
border-top: 1px solid transparent !important;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1) !important;
}
.navbar-fixed-top {
top: 0 !important;
border-width: 0 0 1px !important;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px !important;
}
.navbar-nav>li {
float: none !important;
}
.navbar-nav>li>a {
padding-top: 10px !important;
padding-bottom: 10px !important;
}
.collapse.in{
display:block !important;
}
}
The menu stays open (collapse.in class) and all the dropdowns are shown as normal dropdowns not the mobile version. Does anyone know how i can fix this or even why it is happening when every example ive looked at works perfectly fine.
if you want to solve your problem with bootstrap you have to define your custom responsive grid-float-breakpoint(#grid-float-breakpoint).To do this you have to customize bootstrap variables.less file. here is a Instructions also here. Other way you can manipulate your navbar with Jquery some example. I hope it helps
Just add #autocollapse to your nav tag. see code
function autocollapse() {
var navbar = $('#autocollapse');
navbar.removeClass('collapsed');
if(navbar.innerHeight() > 50) // check if we've got 2 lines
navbar.addClass('collapsed');
}
#autocollapse.collapsed .navbar-header {
float: none;
}
#autocollapse.collapsed .navbar-toggle {
display: block;
}
#autocollapse.collapsed .navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
#autocollapse.collapsed .navbar-collapse.collapse {
display: none!important;
}
#autocollapse.collapsed .navbar-nav {
float: none!important;
margin: 7.5px -15px;
}
#autocollapse.collapsed .navbar-nav>li {
float: none;
}
#autocollapse.collapsed .navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
<nav id="autocollapse" class="navbar navbar-default" id="navigation-top-affix">

How to change the background color of bootstrap navbar?

I'm currently working on a theme and there I got this weird sort of problem which I'm here sharing for solution, I want to change the bootstrap navbar color from default to #0288D1 but even though I have mentioned this hex-code in background-color property of navbar class I haven't got the desired result.
Here is the HTML Code
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#menu">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"></a>
</div>
<div class="collapse navbar-collapse" id="menu">
<ul class="nav navbar-nav navbar-right">
<li>ABOUT</li>
<li>SERVICES</li>
<li>PORTFOLIO</li>
<li>PRICING</li>
<li>CONTACT</li>
</ul>
</div>
</div>
CSS
.navbar {
margin-bottom: 0;
background-color: #0288D1;
z-index: 9999;
border: 0;
font-size: 12px !important;
line-height: 1.42857143 !important;
letter-spacing: 4px;
border-radius: 0;
}
.navbar li a, .navbar .navbar-brand {
color: #fff !important;
}
.navbar-nav li a:hover, .navbar-nav li.active a {
color: #0288D1 !important;
background-color: #fff !important;
}
.navbar-default .navbar-toggle {
border-color: transparent;
color: #fff !important;
}
You can replace it with w/e color you want.It works fine to me , I dont experience any problems? Even with hex-code color;
.navbar{
background-color: red;
}