Bootstrap Navbar with Logo Centered Inside Navbar - html

Logo Centered Inside Navbar
I try to achieve it using bootstrap..
But I don't want to collapse the logo part, only collapse other li.
<header role="banner">
<nav id="navbar-primary" class="navbar" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-primary-collapse">
<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" id="navbar-primary-collapse">
<ul class="nav navbar-nav">
<li><a href="#"><span class="glyphicon glyphicon-home"
aria-hidden="true"></span> Home</a></li>
<li style="margin-right: 80px"><a href="articles.html"><i class="fa fa-pagelines" aria-hidden="true"></i>
Articles</a></li>
<li style="margin-left: 80px"><a href="signIn.html"><i class="fa fa-sign-in" aria-hidden="true"></i>
Sign in</a></li>
<li class="active"><a href="signUp.html"><i class="fa fa-sign-in" aria-hidden="true"></i>
Sign up</a></li>
</ul>
</div>
<div style="float:none">
<img src="../image/uoblogo.png" height="60px" width="200px" >
</div>
</div>
</nav>
</header>

This has basically been answered on SO before. You'll need to tweak the CSS for your image height, etc.., and keep the navbar-brand out of the navbar-collapse
.navbar-brand {
position: absolute;
width: 100%;
left: 0;
top: 0;
text-align: center;
margin: auto;
}
.navbar-brand > img {
display: initial;
}
.navbar-toggle {
z-index:3;
}
http://www.codeply.com/go/G5uYBjmKkf

Move image inside the ul and apply vertical-align to each li would fix your issue
check this codepen
change your mark up to the following
<header role="banner">
<nav id="navbar-primary" class="navbar" role="navigation">
<ul class="nav navbar-nav">
<li>
<a href="#">
<span class="glyphicon glyphicon-home icon" aria-hidden="true"></span> Home</a>
</li>
<li>
<i class="fa fa-pagelines icon" aria-hidden="true"></i>Articles
</li>
<li>
<i class="icon fa fa-sign-in" aria-hidden="true"></i>Sign in
</li>
<li class="img">
<img src="https://lh6.googleusercontent.com/-lLR_c-yGAKc/AAAAAAAAAAI/AAAAAAAAGoY/3TnWGhgp4-0/s0-c-k-no-ns/photo.jpg" height="60px" width="200px">
</li>
<li class="active">
<i class="icon fa fa-sign-in" aria-hidden="true"></i>Sign up
</li>
</ul>
</nav>
</header>
and css to the following
ul li a{
line-height:50px!important;
vertical-align:bottom;
}
Hope it helps

Related

How can i modify this bootstrap code?

I found a code from
http://usebootstrap.com/theme/facebook
But in this code, I want to make 'Home icon' never be collapsed at any browser size.
CODE:
<div class="navbar navbar-blue navbar-static-top">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
b
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
###▽▽▽ I want this icon remain on the navbar, not in collapsed dropdown menu
<i class="glyphicon glyphicon-home"></i>
###△△△ I want this icon remain on the navbar, not in collapsed dropdown menu
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<i class="glyphicon glyphicon-user"></i>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
</div>
Bootply: https://www.bootply.com/lEfd188zDg
I tried to move <i class="glyphicon glyphicon-home"></i> to after b, but it looks very ugly.
I want that 'Home icon' is still seen in smaller browser size, being looks nicely not ugly. How can i modify well?
EDIT
Pic:
This simplified code is a little different from above code that i posted firstly.
Simplified code:
<div class="wrapper">
<div class="box">
<div class="row row-offcanvas row-offcanvas-left">
<div class="column col-sm-12 col-xs-12" id="main">
<!-- top nav -->
<div class="navbar navbar-blue navbar-static-top">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<i class="glyphicon glyphicon-user"></i>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
<!-- /top nav -->
</div>
</div>
</div>
</div>
</div>
original result is like:
and in narrow browser,
But purpose result is like:
Would give me the way how to make this?
I just updated your HTML code and added CSS. Just replace it with yours. Please Only tap nav.
<style>
.heading-icons li{
padding: 9px 10px;
margin-top: 8px;
margin-right: 15px;
}
</style>
<div class="navbar navbar-blue navbar-static-top">
<div class="col-xs-6 col-sm-6">
<ul class="list-inline heading-icons">
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
<li>
<i class="glyphicon glyphicon-home"></i>
</li>
</ul>
</div>
<div class="navbar-header col-xs-6 col-sm-6">
<button class="navbar-toggle" type="button" data-toggle="collapse"
data-target=".navbar-collapse">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i
class="glyphicon glyphicon-user"></i></a>
<ul class="dropdown-menu">
<li>More</li>
<li>More</li>
</ul>
</li>
</ul>
</nav>
<!-- /top nav -->
</div>

How to add two <li> in right of navbar

I have navbar with some <li> at it.
Here is my HTML and CSS code:
<nav class="navbar navbar-default navbar-fixed-top navbar-centered" role="navigation">
<div class="container" style="position: relative">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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 page-scroll" href="#page-top">
<img src="~/Images/logo.png" /></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
<a class="page-scroll" href="#page-top"></a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#about">About Us</a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#services">Benefits</a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#contact">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
I need to add there two <li>, but it need to be at right of navbar.
Something like this:
How I can do this?
<nav class="navbar navbar-default navbar-fixed-top navbar-centered" role="navigation">
<div class="container" style="position: relative">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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 page-scroll" href="#page-top">
<img src="~/Images/logo.png" /></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav" style="float:left">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
<a class="page-scroll" href="#page-top"></a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#about">About Us</a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#services">Benefits</a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#contact">Contact</a>
</li>
</ul>
<ul style="float:right">
<li><a>Try it Risk free</a></li>
<li><a>login</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
You can add another <ul> element with navbar-right class to it
<nav class="navbar navbar-default navbar-fixed-top navbar-centered" role="navigation">
<div class="container" style="position: relative">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-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 page-scroll" href="#page-top">
<img src="~/Images/logo.png" /></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
<a class="page-scroll" href="#page-top"></a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#about">About Us</a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#services">Benefits</a>
</li>
<li style="margin-left: 35px; margin-top: 10px;">
<a class="page-scroll" href="#contact">Contact</a>
</li>
</ul>
//this is the nav elments towards right
<ul class="nav navbar-nav navbar-right">
<li>Right Link1</li>
<li>Right Link 2</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
You can use display flex on the Nav
CSS
ul.nav{
display:flex;
align-items: flex-start;
}
ul.nav li.right{
align-self: flex-end;
color: red;
border: 2px solid red;
}
HTML
ul.nav
li*3 // normal links
li.right*2 // sign up links

Display icons inline with navigation

My html markup is:
<div class="row">
<div class="col-sm-8">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" 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>
</div>
<!-- navbar-header -->
<nav class="collapse navbar-collapse navigation" id="navbar-collapse">
<ul class="nav navbar-nav menu">
<li>Home</li>
<li>Features</li>
<li>Lifestyle</li>
<li>Travel</li>
<li>Music</li>
<li>About</li>
<li>Contact Me</li>
</ul>
</nav>
</div>
<!-- navbar-collapse -->
<div class="col-sm-4 navigation" id="social-icons">
<ul class="menu">
<i class="fa fa-facebook"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-instagram"></i>
<i class="fa fa-pinterest"></i>
<i class="fa fa-heart"></i>
<i class="fa fa-google-plus"></i>
<i class="fa fa-tumblr"></i>
</ul>
</div>
<!-- social-icons -->
</div><!-- row -->
</div>
<!-- container -->
</nav>
While resizing window, the lists stack probably because i have used the grid system.
But what I want to achieve is that the responsive menu(the three lines) be pulled to the left and the icons remain at their place.
I am trying to learn web development on my own. Any help/suggestion would be appreciated.
Edit 1:
After using media query to set the position of the icons to relative, i have achieved this.
I want the icons to be on the right side and the menu to be on the left side.
set position:relative to the parent div then Try with this
#media (max-width:767px){
#social-icons {
position:absolute;
top:15px; /*or whatever you need*/
}
}
Try with the code snippet
.navbar-toggle {
background: #000;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<style>
.navbar-toggle {
background: #000;
float:left;
}
#social-icons {
position: absolute;
top: 15px;
right: 15px;
}
</style>
<div class="col-sm-8">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" 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>
</div>
<!-- navbar-header -->
<nav class="collapse navbar-collapse navigation" id="navbar-collapse">
<ul class="nav navbar-nav menu">
<li>Home</li>
<li>Features</li>
<li>Lifestyle</li>
<li>Travel</li>
<li>Music</li>
<li>About</li>
<li>Contact Me</li>
</ul>
</nav>
</div>
<!-- navbar-collapse -->
<div class="col-sm-4 navigation" id="social-icons">
<ul class="menu">
<i class="fa fa-facebook"></i> <i class="fa fa-twitter"></i> <i class="fa fa-instagram"></i> <i class="fa fa-pinterest"></i> <i class="fa fa-heart"></i> <i class="fa fa-google-plus"></i> <i class="fa fa-tumblr"></i>
</ul>
</div>
<!-- social-icons -->
</div>
<!-- container -->
</nav>
<!--/.nav-collapse -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

Changing the width of links/buttons on a Bootstrap navbar

I had a question about the sizing/width of buttons in a Bootstrap Navbar. I tried setting the width of each of them to 50% in my main CSS file so that it would fit in the Nav, and I'm still not having any luck. It seems like there's a lot of space between links which I want to get rid of. Could someone help me figure out what I'm doing wrong?
HTML
<nav class="navbar navbar-default navbar-fixed-top" role="navigation" bs-navbar>
<div class="navbar-header">
<a class="navbar-brand navbar-left" href="#">Brand</a>
</div>
<ul class="nav nav-justified navbar-right">
<li data-match-route="/$">Home</li>
<li data-match-route="/page-one">Page One</li>
<li data-match-route="/page-two.*">Page Two</li>
<li>
<a class="btn btn-sm btn-secondary-outline" href="/users/sign_up" id="SignUp">SIGN UP</a>
</li>
<li>
<a class="btn btn-sm btn-primary-outline" href="/users/sign_in" id="SignIn">SIGN IN</a>
</li>
<li>
<a class="btn btn-sm btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
</ul>
</nav>
CSS
#HomeNav {
max-width: 50%;
}
(for example)
It's easy, your <ul>tag was not set up correctly, change it to this <ul class="nav navbar-nav">
HTML:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation" bs-navbar>
<div class="navbar-header">
<a class="navbar-brand navbar-left" href="#">Brand</a>
</div>
<ul class="nav navbar-nav">
<li data-match-route="/$">Home</li>
<li data-match-route="/page-one">Page One</li>
<li data-match-route="/page-two.*">Page Two</li>
<li>
<a class="btn btn-sm btn-secondary-outline" href="/users/sign_up" id="SignUp">SIGN UP</a>
</li>
<li>
<a class="btn btn-sm btn-primary-outline" href="/users/sign_in" id="SignIn">SIGN IN</a>
</li>
<li>
<a class="btn btn-sm btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
</ul>
</nav>
Demo: CodePen Example
Maybe this well help. If you're trying to have evenly spaced or justified links that you may need to add to.
You can change the display to table-cell and remove the floats from the navbar.
See working example Snippet.
#media (min-width: 767px) {
.navbar.navbar-custom .navbar-nav {
margin: 0;
display: table;
width: 100%;
}
.navbar.navbar-custom .navbar-nav > li {
display: table-cell;
float: none;
}
.navbar.navbar-custom .navbar-nav > li > a {
text-align: center;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-custom" role="navigation">
<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-navbar" 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>
</div>
<div class="collapse navbar-collapse" id="bs-navbar">
<ul class="nav navbar-nav">
<li data-match-route="/$">Home
</li>
<li data-match-route="/page-one">Page One
</li>
<li data-match-route="/page-two.*">Page Two
</li>
<li> <a class="nav-btn btn-secondary-outline" href="/users/sign_up" id="SignUp">SIGN UP</a>
</li>
<li> <a class="nav-btn btn-primary-outline" href="/users/sign_in" id="SignIn">SIGN IN</a>
</li>
<li> <a class="nav-btn btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
<li> <a class="nav-btn btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
<li> <a class="nav-btn btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
<li> <a class="nav-btn btn-gray-outline" href="/professionals/sign_in" id="People">People</a>
</li>
</ul>
</div>
</div>
</nav>

Hamburger menu causing navbar elements to fall outside nav

Hi when I resize the browser window in chrome/safari (not an issue in FF) the navbar transforms into hamburger menu, as I have coded for. But when I return to desktop size, the menu elements have fallen outside the navbar.
Here is the header section of my code:
<!-- ******HEADER****** -->
<header id="header" class="header">
<div class="container">
<img src="assets/images/figures/logo.png">
<nav class="main-nav navbar-right" role="navigation">
<div class="navbar-header">
<button class="navbar-toggle" type="button" 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><!--//nav-toggle-->
</div><!--//navbar-header-->
<div id="navbar-collapse" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active nav-item"><i class="fa fa-home"> Home</i></li>
<li class="nav-item"><i class="fa fa-question"> Who</i></li>
<li class="nav-item"><i class="fa fa-area-chart"> What</i></li>
<li class="nav-item"><i class="fa fa-location-arrow"> Where</i></li>
<li class="nav-item"><i class="fa fa-ticket"> Tickets</i></li>
<!-- <li class="nav-item dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="0" data-close-others="false" href="#">Info <i class="fa fa-angle-down"></i></a>
<ul class="dropdown-menu">
<li class="nav-item"><i class="fa fa-location-arrow"> Mission Statement</i></li>
<li class="nav-item"><i class="fa fa-ticket"> Press</i></li>
</ul> -->
</ul>
<!--//nav-->
</div><!--//navabr-collapse-->
</nav><!--//main-nav-->
</div><!--//container-->
</header><!--//header-->
And my styles.css can be seen here: http://178.62.123.221/styles.css
Can anyone advise how I may fix this issue?
Thanks in advance.
Try adding your logo wrapper a proper float, so it doesn't interfere the way your navigation is positioned:
(better add a class to it, but) for now:
#header > .container > a{
float: left;
}