I'm trying to center my logo in boostrap navbar.
I've been searching numerous ways and I found some that worked for me but the center content would cover all of the navbar (unable to click on other links).
So I wrote my own code. Pull left and right are working with no problems, but my center wont center!
Here are my codes.
(I've set the background color to be red on my center content so I have an idea of it's size and area)
The HTML
<nav class="navbar navbar-default" role="navigation">
<div class="navbar navbar-fixed-top">
<!--LEFT OF NAVBAR-->
<div class="navbar-header pull-left">
<a class="navbar-brand" href="#">
<span class="glyphicon glyphicon-align-left"></span>
</a>
</div>
<!--CENTER OF NAVBAR-->
<div class="navbar-header center">
<a class="navbar-brand" style="background:red;" href="#">Center</a>
</div>
<!--RIGHT OF NAVBAR-->
<div class="navbar-header pull-right">
<a class="navbar-brand" href="#" style="font-size:1em;">Sign In</a>
</div>
</div>
</nav>
The CSS
.center {
display:inline-block;
float:none;
margin-left:auto;
margin-right:auto;
text-align:center;
}
Here is my jsfiddle.
http://jsfiddle.net/ew64yt63/
You could add text-align:center to .navbar
Demo Fiddle
.navbar {
text-align:center;
}
Note that you may then need to change the text alignment for child elements.
Alternatively, you can offset and transform the element, e.g:
Demo Fiddle
.center {
display:inline-block;
position:relative;
left:50%;
transform:translateX(-100%);
}
Related
I am trying to create Navbar for the website with two rows and margin-top: 0 for the top row. This code works but couldn't align the top row with zero margin.
---------------------------------------------------------------------
icon-image(small icon) slogan(text)
Site Logo company name
----------------------------------------------------------------------
Code.
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<nav class="navbar-inverse nav-upper">
<div class="container-fluid">
<ul class="nav navbar-upper">
<li>
<a class="navbar-brand" href="#">
<span><img src="~/lib/images/icn.png" /></span>
website slogan
</a>
</li>
</ul>
</div>
</nav>
<div class="navbar-header">
<a class="navbar-brand" href="#">
<span><img src="~/lib/images/_image1.png" /></span>
Company Name
</a>
</div>
</div>
</div>
CSS
.nav-upper ul.navbar-upper li {
margin-top: 0;
}
Is it something like that you want ?
Bootply : https://www.bootply.com/N7NZzIDoVm
Css :
.nav-upper ul.navbar-upper li {
margin-top: 0;
}
.nav-upper > div {padding:0;}
I am in trouble in my project for using bootstrap nav.
After nav is jumbotron div, but there is a bland gap between nav and jumbotron.
I have trid define nav:
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
"navbar-fixed-top" can delete bland gap, but nav has hidden part of jumbotron. So the content of jumbotron is not in the middle of container.
Here is my code:
<style>
.navbar .nav li.active a:hover{color:#51c3e1}
</style>
<nav class="navbar navbar-inverse" role="navigation">
<div class="container-fluid" style="height:70px">
<div class="navbar-header">
<a class="navbar-brand" href="#"><img src="pic/logo.png" style="width:130px;height:40px;top:1px"></a>
</div>
<div></div>
</div>
</nav>
<div class="jumbotron">
<div class="container">
<h1 style="white">Hello!</h1>
<p style="white">I love this world!!</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more ยป</a></p>
</div>
</div>
It seems nothing wrong, who can help me?
I have found the solution:
.navbar { margin-bottom:0px}
Before Start, I have searched for the last few hours, found several replies but none that fixed this issue.
I only have one link, and I have a fixed to top navbar. I want the Link to stay on the same line as the Brand in mobile/smaller screens.
Right now on mobile (Ref image below):
I have tried floating it right to see if that helped, but it didn't.
HTML:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a></div>
<div class="collapse navbar-collapse" id="topFixedNavbar1">
<ul class="nav navbar-nav">
<li class="active">1 Link Only<span class="sr-only">(current)</span></li>
</ul>
</div>
</div>
</nav>
CSS:
.navbar-collapse.collapse {
display: inline-block!important;
}
.navbar-nav>li, .navbar-nav {
float: left !important;
}
You only need to delete collapse navbar-collapse classes and use a custom class. You can name it custom-navbar-nav. Finally, add the CSS showed here. If you definitely want your link on the top, you need to use media queries.
.navbar-header {
display: inline-block;
}
.custom-navbar-nav {
display: inline-block;
float: right;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a></div>
<div class="custom-navbar-nav">
<ul class="nav navbar-nav">
<li class="active">1 Link Only<span class="sr-only">(current)</span></li>
</ul>
</div>
</div>
</nav>
In the below Bootstrap 3 code, the nav bar will wrap vertically when in an iPhone. How do I prevent the vertical stacking. I wish it to stay horizontal on the bottom in one line.
<div class="navbar navbar-default navbar-fixed-bottom">
<div class="navbar-header">
<a class="navbar-brand" href="#">Ny Title</a>
</div>
<ul class="nav navbar-nav">
<li> 123 </li>
<li> 123 </li>
</ul>
</div>
Found it:
<style type="text/css">
.navbar-nav>li {
float: none;
text-align: center;
display: inline-block;
}
</style>
I am trying to built a site with Bootstrap. So far everything is going pretty much as planned. I would like a fixed navbar and I am using the built in function:
<div class="navbar navbar-fixed-top">
This is great and just what I need BUT I would like the navigation and title to start at the same place as the container instead of all the way to the left/right (still having the navbar going 100% in width. I have tried to put a container inside the navbar which was not the correct solution :-)
example
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="./index.html">Bootstrap</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active">
Home
</li>
<li>
Get started
</li>
...
<li>
Customize
</li>
</ul>
</div>
</div>
</div>
</div>
or throw
.navbar {
max-width: 1170px; /* width of .container */
margin: 0 auto;
}
into the css
You should have a container class nested inside your navbar
<div class="navbar navbar-fixed-top">
<div class="container">your menu and logo go here</div>
</div>
That will give you the same width as the body container if you do not have a fluid layout and will give auto margins to the container so it is centered in the middle of the screen. It will also keep the navbar itself at 100%