NAVBAR Loss of responsiveness in mobile view - html

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

Related

Hamburger menu dropdown on the right side

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;
}

How to add dropdown below the navbar in bootstrap 3.3.7

So I am trying to make my dropdown actually appear below the navbar like in the shown picture
Here is my html:`
<div class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed"
data-toggle="collapse" data-target="#myNavbar">
<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 logo" href="#"></a>
</div>
<div class="collapse navbar-collapse navbar-right" id="myNavbar">
<ul class="nav navbar-nav">
<li class="dropdown"><a href="#" class="dropdown-toggle"
data-toggle="dropdown" role="button" aria-expanded="false">blah
<!-- <span class="caret"></span> -->
</a>
<ul class="dropdown-menu" role="menu">
<li>blah1</li>
<li>blah 2</li>
<li>blah 3</li>
</ul></li>
<li>blah</li>
<li class="dropdown"><a href="#" class="dropdown-toggle"
data-toggle="dropdown" role="button" aria-expanded="false">blah
</a>
<ul class="dropdown-menu" role="menu">
<li>blah</li>
<li>blah & blah</li>
<li>blah</li>
</ul></li>
<li> blah</li>
<li>blah</li>
<li><img src="../images/search.png"/></li>
<li>Login</li>
</ul>
</div>
</div>
</nav>
</div>
Here is my css:
.icon--house, .modal button, article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block
}
.navbar-default {
background-color: #030303 !important;
border: #030303;
}
.nav > li > a {
padding: 25px 20px;
font-size: 16px;
}
/* bigger menu items in dropdown */
.dropdown-menu > li > a {
padding: 20px;
}
/* removes whitespace in dropdown from navbar */
.dropdown-menu {
padding: 0;
float: right;
left: 50% !important;
right: auto !important;
text-align: center !important;
transform: translate(-50%, 0) !important;
}
.dropdown:hover .dropdown-menu {
display: block;
}
.dropdown-menu>li>a:hover {
color: #FFF;
background-color: #da1a32;
text-decoration: none;
}
.navbar .navbar-nav > li > a {
color: #FFF !important;
border-bottom: transparent solid 3px;
padding-bottom: 5px;
}
.navbar .navbar-nav > li > a:hover {
border-bottom: #da1a32 solid 3px;
}
a:link {
text-decoration: none;
color: #FFF !important;
}
a:visited {
text-decoration: none;
color: #FFF;
}
a:hover {
text-decoration: none;
color: #FFF;
}
a:active {
text-decoration: none;
color: #FFF;
}
.align-center, .missing {
text-align: center
}
body {
font-family: Montserrat, sans-serif;
font-weight: 300;
line-height: 1.4;
color: #202020;
overflow-x: hidden
}
img {
max-width: 100%;
height: auto
}
a {
transition: .3s ease;
text-decoration: none
}
h1 {
font-size: 30px;
line-height: 1.1;
margin-bottom: .5em
}
this is what I want it to appear like:
And this is what It looks like overlapping the actual navbar:
I've tried some different things such as adding a margin to the bottom of my header but it did not help. If anyone could help it would be greatly appreciated, as I'm not sure where to go from here. If you could also tell me exactly what css it was that needed to be change that would be great. Thanks.
You just need to adjust the 'top' value on the .dropdown-menu class, which is absolute positioned. probably at 100% now
.dropdown-menu {
top: 100%;
}
this will make it line up with the bottom of the li.dropdown > a element,
so if you have 20 extra px of black background from navbar padding, try this:
.dropdown-menu {
top: calc(100% + 20px);
}

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!

Adding a white background to bootstrap navbar items

I am working on making a personal site by playing around with bootstrap and I have a transparent navigation bar that looks like this:
Written like this:
<nav class="navbar navbar-default navbar-fixed-top navbar-shrink">
<div class="container">
<div class="navbar-header page-scroll">
<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" href="#home">Jon Snow - Knows Nothing</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="page-scroll">
About Me
</li>
<li class="page-scroll">
Work
</li>
<li class="page-scroll">
Blog
</li>
<li class="page-scroll">
Contact Me
</ul>
</div>
</div>
</nav>
This how the CSS is setup with different profiles for desktop and mobile sites:
#media only screen
and (min-width: 768px) {
.navbar.navbar-default {
padding:6px;
background: rgba(0, 0, 0, 0);
border: none;
}
.navbar.navbar-default .navbar-nav > li > a,
.navbar.navbar-default .navbar-brand {
color: white;
}
.navbar.navbar-default .navbar-collapse {
border: none;
box-shadow: none;
}
}
#media only screen and (max-width: 767px) {
.navbar.navbar-default {
background: rgba(0, 0, 0, .5);
border: none;
}
.icon-bar {
background-color:#ffffff !important;
}
.navbar.navbar-default .navbar-nav > li > a,
.navbar.navbar-default .navbar-brand {
color: white;
}
.navbar.navbar-default .navbar-collapse {
border: none;
box-shadow: none;
}
I am trying to add a highlight on hover and focus to my navbar item that is supposed to look like this:
I tried variations of this but no luck:
.nav li > a {
background-color:#000000;
color: #ffffff;
}
Also here is fiddle: JSFiddle
This may work!
.navbar.navbar-default .navbar-nav li a:hover {
background-color:#000000;
color: #ffffff;
border-radius:5px;
}

Content inside a div block not aligning vertically

I have a fixed-top navigation bar with content inside that needs to be center aligned vertically. Additionally, I'm using bootstrap to me design my page. The navigation bar has two major content blocks. One is an image as my nav header and one has a container of an with links.
The container I wrapped around the two does not have any vertical padding and only has margins for content going underneath it.
<!--Navigation Bar-->
<nav class="navbar navbar-default navbar-fixed-top navbar-wrap">
<div class="container-fluid">
<div class="navbar-header">
<img src="img/logo.png" />
</div>
<ul class="nav navbar-nav navbar-right">
<li>Who Am I?</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
</nav>
What I have tried doing is set the .container-fluid>ul to be relative to the container and set the margin to auto. I do not want to have a fixed margin or padding for it since I want the site to scale well even on mobile devices (hence why I'm using bootstrap).
I am a very amateur developer and just trying to get a site off the ground so I can showcase my projects from school and side gigs.
Thanks in advanced, if you would like to see my CSS. I can edit it in too.
http://imgur.com/pXcwav3
.navbar-wrap {
padding: 0;
background-color: #77B69C;
}
.nav {
padding-right: 15px;
}
.navbar-right {
margin-right: 0;
}
.container-fluid>ul {
position: relative;
height: 100%;
margin: auto;
}
.navbar-default .navbar-nav>li>a {
color: #ECF0F1;
border-radius: 5px;
transition: background-color 0.5s;
}
.navbar-default .navbar-nav>li>a:hover {
color: #171F26;
background-color: #fff;
}
There are multiple ways you can handle this depending on what makes most sense.
1) You could actually use text and adjust it with CSS like in the first
navbar example.
2) You can constrain the image to the navbars default height like in
example 2.
3) And you can adjust the height and line height like in example 3 for an
image that exceeds the height of the navbar.
** Also, if you are using a preprocessor (LESS or SASS) you can easily adjust the height and the rest is handled.
I also inserted the HTML so your navbar collapses (Navbar Docs)under 768px into the mobile configuration (unsure if the omission was meant or not).
(if you do use the 2nd or 3rd option just remove the margin-top class from navbar-wrap* so the nav is fixed to the top again.)
#import url(https://fonts.googleapis.com/css?family=Hind+Vadodara);
/**Text CSS**/
.navbar.navbar-wrap {
background: #77B69C;
}
.navbar a.navbar-brand,
.navbar a.navbar-brand:hover,
.navbar a.navbar-brand:focus {
font-family: 'Hind Vadodara', sans-serif;
font-size: 30px;
color: #000;
letter-spacing: 5px;
}
.navbar .navbar-brand span.lname {
color: #fff;
}
.navbar.navbar-wrap .navbar-nav > li > a {
font-family: 'Hind Vadodara', sans-serif;
color: #ECF0F1;
border-radius: 5px;
transition: background-color 0.5s;
}
.navbar.navbar-wrap .navbar-nav > li > a:hover {
color: #171F26;
background-color: #fff;
}
#media (min-width: 768px) {
.navbar.navbar-wrap .navbar-right {
margin-right: 15px;
}
.navbar.navbar-wrap .navbar-brand {
margin-left: 15px;
}
}
/**IMG CSS**/
.navbar.navbar-wrap2 .navbar-brand {
padding: 0;
margin: 0;
}
.navbar.navbar-wrap2 .navbar-brand img {
height: 50px;
width: 300px;
padding: 0;
margin: 0;
left: 0;
}
.navbar.navbar-wrap2 {
background: #77B69C;
margin-top: 200px;
}
.navbar.navbar-wrap2 .navbar-nav > li > a {
font-family: 'Hind Vadodara', sans-serif;
color: #ECF0F1;
border-radius: 5px;
transition: background-color 0.5s;
}
.navbar.navbar-wrap2 .navbar-nav > li > a:hover {
color: #171F26;
background-color: #fff;
}
.navbar.navbar-wrap2 .navbar-brand img {
margin-left: 15px;
}
#media (min-width: 768px) {
.navbar.navbar-wrap2 .navbar-right {
margin-right: 15px;
}
}
/**LARGE IMG CSS**/
.navbar.navbar-wrap3 .navbar-brand {
padding: 0;
margin: 0;
}
.navbar.navbar-wrap3 .navbar-brand img {
height: 75px;
width: 300px;
padding: 0;
margin: 0;
left: 0;
}
.navbar.navbar-wrap3 {
background: #77B69C;
margin-top: 400px;
}
.navbar.navbar-wrap3 .navbar-header {
height: 75px;
}
.navbar.navbar-wrap3 .navbar-toggle {
margin-top: 20px;
}
.navbar.navbar-wrap3 .navbar-nav > li > a {
font-family: 'Hind Vadodara', sans-serif;
color: #ECF0F1;
border-radius: 5px;
transition: background-color 0.5s;
}
.navbar.navbar-wrap3 .navbar-nav > li > a:hover {
color: #171F26;
background-color: #fff;
}
.navbar.navbar-wrap3 .navbar-brand img {
margin-left: 15px;
}
#media (min-width: 768px) {
.navbar.navbar-wrap3 .navbar-right {
margin-right: 15px;
}
.navbar.navbar-wrap3 .navbar-nav > li > a {
line-height: 45px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-wrap navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav" 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" href="#"><span class="fname">James</span> <span class="lname">Wong</span></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-nav">
<ul class="nav navbar-nav navbar-right">
<li>Who Am I?
</li>
<li>Projects
</li>
<li>Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<hr>
<nav class="navbar navbar-default navbar-wrap2 navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav2" 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" href="#">
<img src="http://academe.co.uk/wp-content/uploads/2014/10/sugarcrmLogoWhiteBackground_RGB.png" />
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-nav2">
<ul class="nav navbar-nav navbar-right">
<li>Who Am I?
</li>
<li>Projects
</li>
<li>Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<hr>
<nav class="navbar navbar-default navbar-wrap3 navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-nav3" 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" href="#">
<img src="http://academe.co.uk/wp-content/uploads/2014/10/sugarcrmLogoWhiteBackground_RGB.png" />
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-nav3">
<ul class="nav navbar-nav navbar-right">
<li>Who Am I?
</li>
<li>Projects
</li>
<li>Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>