how to make nav brand centrally aligned - html

I have the following code, what I'm trying to do is get the nav logo centered with equal pixels either side so the link on the left and right have the same distance between them.
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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>
</div>
<a class="navbar-brand" href='#Url.Action("Index", "Home")'></a>
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li>#Html.ActionLink("PRODUCTS", "Products", "Products")</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>VISIT US: <b>f</b></li>
</ul>
</div>
</div>
</nav>
and this is my CSS
.navbar-brand {
background-image: url("/Content/Images/Brand-Background-New5.png");
background-repeat: no-repeat;
display: block;
height: 94px;
left: 42%;
margin: auto;
position: absolute;
text-align: center;
top: 16%;
width: 301px;
z-index: 9999;
}
now on large screens i.e dessktops the above works fine, but when I minimize the browser, or someone opens the website on say a 15 inch laptop the navbar-brand is no longer centered it appears more to the right? how can I lock it so it stays centered regardless of the screen size

You can use the CSS calc() function: css calc tutorial
What's happening is that on a small screen, 42% is the space to the left of the nav, the nav itself is taking up like 50% of the screen (since its so small) and you're left with 2% to the right.
What's the width of your nav? width: 301px;
What's the total width of a computer screen? 100%
So the space to the left of a perfectly centered nav should be: (100%-301px)/2
Solving the equation we get: 50%-150px
Just fix that one line in your CSS code to say:
left: calc(50% - 150px);
THE SPACES AROUND THE - (minus) SIGN ARE IMPORTANT
The resulting CSS should be:
.navbar-brand {
background-image: url("/Content/Images/Brand-Background-New5.png");
background-repeat: no-repeat;
display: block;
height: 94px;
left: calc(50% - 150px);
margin: auto;
position: absolute;
text-align: center;
top: 16%;
width: 301px;
z-index: 9999; }

Related

CSS bootstrap fill left part of navigation

Currently I have to implement a complex navigation styling.
I succeeded to simplify the problem to show only the part of the html.
The problem is that I cannot touch the HTML code.
Here is the code (a simple bootstrap navbar):
https://jsfiddle.net/5y4asdef/
I want to fill the space in left of "Application name" for example with white color is such way that to work on all resolutions especially (wider)
I've tried something like this:
.navbar-header:after {
content: " ";
background-color: white;
width: 110px;
height: 80px;
display: block;
position: absolute;
left: 0px;
top: 0;
}
I've tried with combining some background properties, but couldn't figure out how to apply it.
I want to ensure that no matter of how long is the screen it will work:
https://jsfiddle.net/5y4asdef/show (fullscreen)
Use .container-fluid class instead of .container
Here's the updated snippet:
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<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>
<a class="navbar-brand" href="/">Application name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
</ul>
</div>
</div>
</div>
Here is my non-quality solution for now:
.navbar-header {
position: relative;
}
.navbar-header:after {
content: " ";
background-color: white;
width: 1000px;
height: 80px;
display: block;
position: absolute;
left: -1000px;
top: -6px;
}

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

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

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!

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>