Vertically centering Font Awesome icon inside nav - html

I'm trying to make the icon vertically centered so it would align with the rest of the nav links but I can't seem to get it to work no matter what I try.
HTML
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<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>
<img src="img/logo.png" class="navbar-brand" href="index.html">
</div>
<div class="collapse navbar-collapse" id="nav">
<ul class="nav navbar-nav navbar-left">
<li><span class="fa fa-phone"> +62 202 555 0117</span></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
CSS
nav.navbar {
padding: 12px;
}
span.fa.fa-phone {
color: #fff;
vertical-align: middle;
}

Navbar's links have padding: 15px property. So you need to apply this property to the phone number.
Make special class for this purpose. Use
<li class="phone"><span class="fa fa-phone"></span> +62 202 555 0117</li>
instead of <li><span class="fa fa-phone"> +62 202 555 0117</span></li>.
Use <a class="navbar-brand" href="index.html"><img src="img/logo.png" alt=""></a>
instead of <img src="img/logo.png" class="navbar-brand" href="index.html">
The toggle-button has to use the id from <div class="collapse navbar-collapse" id="nav"> as the value of the data-target property.
Please chaeck the result. Is it what you want to achieve?
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
#import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css');
.navbar {
padding: 12px;
}
.nav .phone {
color: #fff;
padding: 15px;
}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#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="index.html"><img src="img/logo.png" alt=""></a>
</div>
<div class="collapse navbar-collapse" id="nav">
<ul class="nav navbar-nav navbar-left">
<li class="phone"><span class="fa fa-phone"></span> +62 202 555 0117</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

Related

how do i align my navbar brand to the center and have my nav links surround it from both sides

I want my navbar brand to be in the middle and my nav links to be positioned on the left and right of my nav brand. Because when the screen reaches md I want the nav links to disappear and be in the burger but still have my nav brand showing at the top center.
<nav class="navbar navbar-expand-md bg-dark navbar-dark py-3">
<div class="container">
<div class="navbar-brand"><h2>Name</h2></div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#burger"><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse" id="burger">
<ul class="navbar-nav mx-auto">
<li class="nav-item px-5">
<h2>Python</h2>
</li>
<li class="nav-item px-5">
<h2>Html&Css</h2>
</li>
</ul>
</div>
</div>
</nav>
I am going for this look
What I want
HTML
<h1 class="text-center">Center Navbar Brand logo</h1>
<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="#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="http://disputebills.com"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTvuVbC_1kQQsg8U63u6gWMWuA7W1Ck5t-zkw&usqp=CAU" alt="logo">
</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-left">
<li class="active">Home</li>
<li>About</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
</div>
CSS
.navbar-brand {
transform: translateX(-50%);
left: 50%;
position: absolute;
}
/* DEMO example styles for logo image */
.navbar-brand {
padding: 0px;
}
.navbar-brand>img {
height: 100%;
width: auto;
padding: 7px 14px;
}
Screenshot

My dropdown menu on mobile devices doesn't work

When I press the menu item on the top right side of my webpage it doesn't collapse. I have checked my code and it seems to be okay.
The website with the problem is: www.kemnet.be
I have tried putting everything in the block and made minor changes to my jquery and CSS.
I have this from a theme and added the original code to my site for testing but the dropdown still doesn't show.
<header class="navbar navbar-inverse navbar-fixed-top opaqued" role="banner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<i class="fa fa-bars"></i>
</button>
<a class="bounce-in no-display animated bounceIn appear" href="index.html"></a> <img src="images\white.png">
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>Praktisch </li>
<li>Onze Visie</li>
<li>Ons Team</li>
<li>Ons Aanbod </li>
<li>Nieuws</li>
<li>Contact</li>
<li><a class="border" href="https://www.mtc-it4.be/patient/index.html#/appointments/day/bjNkcWkyQmFRMkpDVTRFNndleFgzSlRvdC9TSU1YOXdJWklnQ2ZtMDhjcEJCYWl6RlREMWxyOGlZY2FSUk10WQ==" target="_blank">Maak een afspraak</a></li>
</ul>
</div>
</div>
</header>
I don't receive any error messages tho.
I just replaced <i class="fa fa-bars"></i> with classic way.
<header class="navbar navbar-inverse navbar-fixed-top opaqued" role="banner">
<div class="container">
<div class="navbar-header">
<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="bounce-in no-display animated bounceIn appear" href="index.html"></a> <img src="images\white.png">
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>Praktisch </li>
<li>Onze Visie</li>
<li>Ons Team</li>
<li>Ons Aanbod </li>
<li>Nieuws</li>
<li>Contact</li>
<li><a class="border" href="https://www.mtc-it4.be/patient/index.html#/appointments/day/bjNkcWkyQmFRMkpDVTRFNndleFgzSlRvdC9TSU1YOXdJWklnQ2ZtMDhjcEJCYWl6RlREMWxyOGlZY2FSUk10WQ==" target="_blank">Maak een afspraak</a></li>
</ul>
</div>
</div>
</header>
https://jsfiddle.net/v61aeg5r/1/

bootstrap active class background color

I have this HTML for navbar and I need to change the background color for the .active class.
<nav class="navbar navbar-inverse">
<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" id="white" href="#">TableMailerMM</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
<!--<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>-->
</div>
</div>
</nav>
What I have tried is,
.nav.navbar-nav li:active{
background-color: #ff812c;
}
but it doesn't work, any ideas?
Try using
.nav.navbar-nav li.active a{
background-color: red;
}
.nav.navbar-nav li.active a {
background-color: #ff812c;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<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" id="white" href="#">TableMailerMM</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
You're using :active pseudeselector which doesn't apply here use .active class selector and select descendant anchor like :
ul.nav.navbar-nav li.active a {
//styles
}
https://jsfiddle.net/94yqf9sa/4/
:active is about state of element.
.active is about class of element.

Extend Width of Navbar-Right in Bootstrap

I'm having problems extending the navbar-right in Bootstrap. I need it to fit all the elements in it. Here is what's going on:
I can't get the profile image and the username to display separately. I've tried "clear: both" and the normal stuff. When I extend the size of the UL, it breaks the parent DIV. When I try to extend the size of the LI, it doesn't do anything. Here is my code:
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<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 src="images/logo.png" class="logo"> <span class="site-title">Privy Personal</span></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Files</li>
<li class="active">Sharing</li>
<li>Recent</li>
<li>Deleted</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><img src="images/Search.svg"> </li>
<li><img src="images/Notification.svg"> </li>
<li><span class="username">Tony Stark</span><img src="http://placehold.it/25x25" class="profile"></li>
</ul>
</div><!--/.nav-collapse -->
</nav> <!-- End Fixed Nav -->
Can anyone help me?
Add <div class="container-fluid"> after <nav> and adjust the name and picture alignment with margin.
Try this
check demo here
HTML:
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<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="#"><span class="site-title">Privy Personal</span></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Files</li>
<li class="active">Sharing</li>
<li>Recent</li>
<li>Deleted</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><i class="fa fa-user"></i> </li>
<li><i class="fa fa-user"></i> </li>
<li><span class="username">Tony Stark</span><img src="http://placehold.it/25x25" class="profile img-circle"></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>
<!-- End Fixed Nav -->
CSS:
.username {
margin-right: 5px;
}
.profile {
margin-top: -7px;
}
I hope it helps you :)

How to use background image in bootstrap navigation?

I want to use background image in navigation. I have tried to add image through style.css file. But I have tried to using color. This code only takes color not any images. Con anyone explain how it occur & how to solve this ?
<div class="container-fluid header_bg">
<nav class="navbar" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" area-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 src="images/logo.png" alt=""/></a>
</div>
<div id="navbar" class="collapse navbar-collapse" >
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Porfolio</li>
<li>About</li>
<li>Contact Us</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">
<span class="glyphicon glyphicon-user"></span> Sign Up</a>
</li>
<li><a href="#">
<span class="glyphicon glyphicon-log-in"></span> Login</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
In style.css file :
.header_bg {background-image:url("images/header_bg.png") repeat-x scroll 0 0;}
Shorthand property for background is simply "background".
Use following css:
.header_bg {background:url("images/header_bg.png") repeat-x scroll 0 0;}
Here your updated code:
.header_bg {background:url("http://i.stack.imgur.com/Bnxz6.jpg") repeat-x scroll 0 0;}
<div class="container-fluid header_bg">
<nav class="navbar" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" area-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 src="images/logo.png" alt=""/></a>
</div>
<div id="navbar" class="collapse navbar-collapse" >
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Porfolio</li>
<li>About</li>
<li>Contact Us</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">
<span class="glyphicon glyphicon-user"></span> Sign Up</a>
</li>
<li><a href="#">
<span class="glyphicon glyphicon-log-in"></span> Login</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
Instead of the background-image, try using background property as
.header_bg {background:url("images/header_bg.png") repeat-x scroll 0 0;}