Bootstrap custom Nav, Adding max-height breaks collapse (removes background) - html

I'm using BS3 and a bunch of custom styling. I know the line of code that's causing the issue, but I can't think of a way to make the navbar not so tall without the height or max-height attribute. Click on the JSFiddle and you'll see that there is no color background when you look at the menu when collapsed (mobile). Simply remove the max-height line and it works, but the navbar is too tall for what I want.
There's a ton of HTML & CSS, so beware the following paste. Note that I'm linking to a custom bootstrap.css as well...
<div class="navbar-wrapper">
<div class="container-fluid">
<nav class="navbar navbar-inverse navbar-static-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="#"><img id="logo" src="http://www.thinkliz.com/dev/midtownaustin/img/midtown-church-austin-logo-white-vector.svg" class="img-responsive"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>
</div>
</div>
CSS:
/* CUSTOMIZE THE NAVBAR
-------------------------------------------------- */
.navbar-wrapper {
position: absolute;
top: 20px;
right: 0;
left: 0;
z-index: 20;
}
.logo {
margin-top: -42px;
}
.navbar-brand img {
height: 290px;
max-height: 130px;
margin-top: -55px;
}
/* RESPONSIVE CSS
-------------------------------------------------- */
#media (max-width: 768px) {
.navbar-brand img {
max-height: 70px;
margin-top: -60px;
}
/* THIS IS WHAT IS BREAKING THE NAV */
.navbar {
min-height: 80px;
max-height: 80px;
}
.navbar-toggle {
margin-top: 23px;
}
}

So are you trying to get the background of the mobile collapsed menu a different color so you can read the text? You could add a custom CSS rule such as:
.navbar-collapse ul {
background-color: #ff0000;
}
I doubt you want red at the background, but it's just an example.

Most often it breaks the layout if you use position absolute without knowing what you really do. Especially when you work with a CSS framework. You have to fix too much and there seems to be no end.
Customize as much as possible with bootstrap and as less as possible by your own. Only that which you can't do with bootstrap.
To make the navbar work with a bigger (custom) logo follow this instruction:
Instruction bootstrap navbar with bigger logo
with your logo and the size of it.
After you have done this, set the background colors for the
.navbar-header and .navbar-collapse. You have a perfect working navbar!

Related

how to affix a boxed navbar

Im using affix to make fixed my navbar when scroll.
But when scroll navbar is not working fine.
I use <header class="container"> to give a boxed look to header website, an center content.
if I would use header without container, header and menu would fit screen side-to-side. In this case the affixed navbar would work fine, fitting screen in the same way (taking 1391px width).
However Im using <header class="container">. And affixed navbar runs out of screen because is taking 1391px width too. Like if it were a side-to-side looked website. It does not adapt to container width.
Do you know how to solve it?
or
is it that bootstrap affix is desing just for stretched sites and no boxed sites?
This is my HTML for nav
<header class="container">
<nav id="custom-bootstrap-menu" class="navbar navbar-default" role="navigation" data-spy="affix" data-offset-top="222">
<div class="container-fluid">
<div class="navbar-header"><a class="navbar-brand" href="#">Home</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-menubuilder"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navbar-menubuilder">
<ul class="nav navbar-nav navbar-left">
<li class="dropdown" class="dropdown">Nosotros <b class="caret"></b>
<ul class="dropdown-menu" role="menu">
<li>Misión, Visión y Objetivos
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</header>
and this is css
header{
border-top-width: 8px;
border-top-style: solid;
border-top-color: #888;
}
.affix {
position: fixed;
top: 0;
width: 100%;
z-index: 1;
right: 10%;
left: 10%;
}
.affix + .container-fluid {
padding-top: 70px;
}
Take a look here it is similar to what is happening to me. Make result screen smaller and bigger to see what happens
Without codes, I can only assume how your codes look like.
Using twitter bootstrap's navbar fixed navbar example, you need to change .navbar-fixed-top right and left values. Using 0 sets it from side to side.
#media (min-width: 768px) {
.navbar-fixed-top {
position: fixed;
right: auto;
left: auto;
}
}
After that, to make them all align, you would have to overwrite bootstrap's margins (for eg .navbar-right of you have that, etc).
See the fiddle: https://jsfiddle.net/jennift/o7utddud/2/
On a larger screen, you want the #nav.affix to follow the container size. Using 0 on left and right, uses the container as a guide, "stretching" it only as wide as the container.
On a smaller screen, the container now has the width of "auto" and with a fixed position it will stretch left to right. Using a padding of 20px (as used by the bootstrap css), you can realign it to the length of the header container.
#nav.affix {
position: fixed;
top: 0;
left:0;
right:0;
}
#media (max-width: 767px) { /*controls on smaller screen*/
#nav.affix {
left:20px; /*20px to follow bootstrap body padding */
right:20px;
}
}
Fiddle: http://jsfiddle.net/jennift/hnkutxsn/3/

Bootstrap "navbar-brand" causing "navbar-nav" items to shift right from centered position in nav bar?

I am trying to create a navigation bar that has the "brand" (LOGO) on the left side, and the actual navigation items in the center of the entire bar. I am using the default Bootstrap navbar as I just started to learn web development a week ago. This is what it looks like so far:
However, you can see the navigation items are slightly shifted to the right of the actual center of the page (The heading "This is the HOME page." is exactly centered within the page).
Here are parts of my code that I believe may be relevant:
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
.container-fluid {
background-color: white;
border: none;
box-shadow: none;
}
.content {
padding-top: 65px;
width: 100%;
height: 100%;
}
.navbar .navbar-collapse {
text-align: center;
background-color: cyan;
}
.navbar .navbar-nav {
margin: 1%;
display: inline-block;
float: none;
vertical-align: center;
text-decoration: bold;
text-align: center;
}
.navbar-default {
background-color: white;
box-shadow: none;
text-align: center;
}
.navbar-header {
margin: 1%;
}
<!-- Navigation bar -->
<nav class="navbar navbar-default 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-example-navbar-collapse-1" 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="index.html" id="logo">LOGO</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
I am suspicious of the "navbar-brand" as it seems to interfere somehow when I try to change the text-align for ".navbar .navbar-collapse," (colored cyan just for ease of formatting) which I have set to "center" as other answers on StackOverflow have suggested.
For example, when I change the text-align to "left":
.navbar .navbar-collapse {
text-align: left;
background-color: cyan;
}
the navigation bar looks like this:
Changing the text-align to "right" pushes the navigation items all the way over to the right side of the cyan bar, as expected.
Thus, it appears that the navigation items are being centered between the "navbar-brand" and the right side of the bar rather than between the actual left and right sides of the entire bar.
Does anyone have any suggestions on how to make my navigation items accurately centered within the entire bar, so that they are in line with the heading "This is the HOME page." and not shifted to the right?
There are a few different ways to do this, and I guess it depends on what you are going to do further down the track, but the easiest thing is probably to take the .navbar-brand out of the document flow, so that the .navbar-nav ignores it when centering.
You can do this quite easily by adding something like this:
.navbar-brand {
position: absolute;
}
You can check it out over here: http://codepen.io/anon/pen/PNMBQx
Hope that helps, and good luck!

Header content disappearing when CSS applied for responsive layout (bootstrap file included in html)

I am setting a responsive layout for my personal website, which has worked in a simple example. However I am not getting the same results. It may have something to do with including the Bootstrap files in my html. Below is the html and css code for the responsive layout:
HTML:
<header>
<a href="/" id="logo">
<h1>Brian Weber</h1>
<h2>Engineer | Python Programmer</h2>
</a>
<!-- Navigation bar -->
<nav class="navbar navbar-default" role="navigation">
<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="#">Brian Weber</a>
<p>Engineer</p> -->
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Portfolio</li>
<li>About</li>
<li>Resume</li>
<li>Contact</li>
</ul>
</div>
</div>
</header>
CSS:
#media screen and (min-width: 660px) {
/*********************************
HEADER
*********************************/
.navbar .navbar-default {
float: right;
background: none;
font-size: 1.125em;
margin-right: 5%;
text-align: right;
width: 45%;
}
#logo {
float: left;
margin-left: 5%;
text-align: left;
width: 45%;
}
#logo h1 {
font-size: 2.5em;
}
#logo h2 {
font-size: 1.7em;
margin-bottom: 20px;
}
header {
border-bottom: 5px solid #599a68;
margin-bottom: 60px;
}
}
When I check the code in a browser, the h1 and h2 text do not appear. However when I inspect the element there are placeholders for where the text should be. The text color is already set to black in the main.css. My question is how would I fix this problem so that the layout looks like the picture below? I am thinking maybe there is an issue with the bootstrap files where they are overriding the CSS code.
Correct format for header and navbar
h1 and h2 text disappearing
Add this in your style
#logo
{
z-index:1;
position:relative;
}
The z-index property specifies the stack order of an element.
An element with greater stack order is always in front of an element with a lower stack order. and in your style navbar-default hide the h1 and h2 that's why it's not looking
Make .navbar-default float right when in the larger views. It was covering up the left floating div that contained your name etc.
Add position:relative; and z-index for logo.
#logo {
float: left;
margin-left: 5%;
text-align: left;
width: 45%;
position: relative;
z-index: 1;
}

Collapsed bootstrap menu bar not working

When my web page is shown on small devices the menu collapses as expected but when you click on the collapsed menu icon the menu does not appear. There is a slight adjustment of the vertical height of the page below the menu and the last menu item half appears along the top of the page but the rest of the menu is nowhere to be seen.
My Bootstrap code looks like this:
#myNavbar {
position: relative;
border:none;
}
#myNavbar .nav {
position: absolute;
bottom: 0;
right: 0;
margin-bottom: -10px;
}
.navbar-nav.navbar-right:last-child {
margin-right: 0;
}
.navbar-default {
background:#FFFFFF;
border-left:none;
border-right:none;
border-top:none;
border-bottom:solid;
border-bottom-width:2px;
border-color:#01B6AC;
width:100% !important;
margin-right:0px;
padding-right:0px;
border-radius: 0 !important;
-moz-border-radius: 0 !important;
}
<nav class="navbar navbar-default">
<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>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img class="img-responsive" src="/assets/img/outa.png" width="120px;"/></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav pull-right">
<li>Saved searches</li>
<li>Settings</li>
<li>About</li>
<li>Sign In</li>
</ul>
</div>
</div>
</nav>
Anyone know what I am doing wrong?
You problem is here
#myNavbar .nav {
position: absolute;
}
When you use position:absolute; the element will be positioned absolutely from the first positioned parent div, if it can't find one it will position absolutely from the window. You can refer to THIS question for further info. So what you can do is add #media query and set a size over certain pixels where the position will be absolute. So something like
#media(min-width: 400px) {
#myNavbar .nav {
position: absolute;
bottom: 0;
right: 0;
margin-bottom: -10px;
}
}
just give proper reference of bootstrap.css and bootstrap.js and your code will work fine.

navmenu been pushed to left

here is the fiddle
http://fiddle.jshell.net/tymvH/2/
im designing a responsive website, i wanted my img to be center when user using the smaller screen resolution. so i code the css as below
img.bg {
min-height: 100%;
min-width: 1024px;
width: 100%;
height: auto;
position: fixed;
top: 0;
left: 0;
}
#media screen and (max-width: 1024px) {
img.bg {
left: 50%;
margin-left: -512px;
}
}
but because i pushed the img to left, now my navmenu also been pushed to left. the menu can't show after i clicked on the collapse button.
<div class="navbar navbar-default navbar-fixed-bottom">
<button type="button" class="navbar-toggle" data-toggle="offcanvas" data-recalc="false" data-target=".navmenu" data-canvas=".canvas">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navmenu navmenu-default navmenu-fixed-left">
<a class="navmenu-brand" href="#">Project name</a>
<ul class="nav navmenu-nav">
<li class="active">option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</div>
Ditch the media query, use an div with an background instead of an image, remove the fixed min width, set
background-size:cover;
background-position:center center;
See working JSFiddle
To insert the image from PHP, simply move the background tag to the div style definition:
<div style="background-image:url('<?=$imageurl?>');"></div>