how to align icons bootstrap menu (in collapsed state) - html

I have the following code
<div class="navbar navbar-inverse" role="banner">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">
<h1><img src="images/logo.png" alt="logo"></h1>
</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li><i class="fa fa-2x fa-facebook"></i></li>
<li><i class="fa fa-2x fa-twitter"></i></li>
<li><i class="fa fa-2x fa-youtube-play"></i></li>
</ul>
</div>
</div>
</div>
When I run it in normal mode - it does this..
but when I go into mobile mode - the icons get weirdly aligned.
It becomes like so
How can I make it so the icons are aligned left or right in the mobile mode (when it gets collapsed)

This is what you are looking for
.navbar-brand img{
max-height: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<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="#bs-example-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>
<a class="navbar-brand" href="#">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1000px-Google_2015_logo.svg.png" alt="logo">
</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><i class="fa fa-2x fa-facebook"></i></li>
<li><i class="fa fa-2x fa-twitter"></i></li>
<li><i class="fa fa-2x fa-youtube-play"></i></li>
</ul>
</div>
</div>

I don't find any problem check the snippet, if you want to show the url I can check it.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="navbar navbar-inverse" role="banner">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">
<h1 style="padding:0px;margin:0px;line-height:20px;;"><img src="http://scholar.google.it/intl/it/scholar/images/1x/googlelogo_color_270x104dp.png" style="height:40px;" alt="logo"></h1>
</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li><i class="fa fa-2x fa-facebook"></i></li>
<li><i class="fa fa-2x fa-twitter"></i></li>
<li><i class="fa fa-2x fa-youtube-play"></i></li>
</ul>
</div>
</div>
</div>

Related

Navigation Bar Menu not opening

So basically, I took my friends website template which works on mobile and changed things and now use the template. Although, I am unable to open the mobile menu bar.
Here is the following code for the navbar
<div class="contact-bar">
<div class="container">
<div class="row">
<div class="col-sm-8 align-left">
<head>
<link rel="icon" type="image/ico" href="favicon.ico"></head>
<ul>
<li><i class="fa fa-phone" style="vertical-align: middle; font-size: 19px;"></i> (416) 824-5864</li>
<li><i class="fa fa-envelope"></i> topspintennisstringing#gmail.com</li>
</ul>
</div>
<div class="col-sm-4 align-right">
<ul>
<li><i class="fa fa-instagram" style="color: #000000;"></i></li>
</ul>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-default">
<div class='container'>
<div class="navbar-header">
<button type="button" id='navbar-toggle' class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-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 class="brand">
<img src="assets/img/logofinal.png" alt="logo">
</div>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li>Home</li>
<li>About</li>
<li>Services</li><!--
<li>Conditions</li>
<li>Contact</li>-->
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Contact Us</li>
</ul>
</div>
</div>
I don't know what the problem can be because I directly copied the code although it does not work. Also, when I uploaded his website, it also did not work. There is also no bootstrap version in the bootstrap.min.css file. I also use xampp to host the site while developing.
Thank you for reading this post!

One line social icons in collapsed menu

I have a problem and I couldn't solve it. How to show social icons one line in collapsed menu? I added below code to my css file and nothing changed? Any idea? Thanks in advance
.navbar-right li {
display: inline-block;
}
Here is my navbar code:
<head runat="server">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.0/js.cookie.js" type="text/javascript"></script>
</head>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light style="background-color: #ffffff;">
<div class="d-flex flex-grow-1">
<span class="w-100 d-lg-none d-block"></span>
<a class="navbar-brand d-none d-lg-inline-block" href="https://testsite.com">
<img src="images/logo.png" height="150" dir="ltr" alt="logo">
</a>
<a class="navbar-brand-two mx-auto d-lg-none d-inline-block" href="https://testsite.com">
<img src="images/logo.png" height="100" alt="logo">
</a>
<div class="w-100 text-right">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#myNavbar">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>
<div class="collapse navbar-collapse flex-grow-1 text-center" id="myNavbar">
<ul class="navbar-nav ml-auto flex-nowrap">
<li class="nav-item">
Home
</li>
<li class="nav-item">
About
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><i class="fa fa-facebook fa-lg"></i></li>
<li><i class="fa fa-instagram fa-lg"></i></li>
<li><i class="fa fa-twitter fa-lg"></i></li></ul>
</div>
</div>
</nav>
you can just add bootstrap class names d-inline-flex flex-row to your ul tag with class navbar-nav navbar-right which your social icons are in it it will be like :
<ul class="nav navbar-nav navbar-right d-inline-flex flex-row">
<li><i class="fa fa-facebook fa-lg"></i></li>
<li><i class="fa fa-instagram fa-lg"></i></li>
<li><i class="fa fa-twitter fa-lg"></i></li></ul>
if you need to you can even limit it by width like : d-sm-inline-flex and d-lg-flex for example
or You can give display css : display : inline-flex; and flex-direction : row ; to your ul
.navbar-right {
display: inline-flex;
flex-direction : row;
}
I will do this in your css class
.navbar-right li {
display: flex;
flex-direction: row;
}

Bootstrap navbar adjustment

I try to align my navbar placed at the top of my webpage, but somehow one of items appears straight down "Kontakt".
I would like all items i have to be in same line. Second issue is i cannot make my logo when click on it redirect to my page at the top again.
Code:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<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/ico2.png" class="img-responsive" alt="logo">
</div>
<div class="collapse navbar-collapse text-center" id="bs-example-navbar-collapse-1">
<div class="col-md-8 col-xs-12 nav-wrap">
<ul class="nav navbar-nav">
<li><i class="fa fa-windows"></i> Witamy</li>
<li><i class="fa fa-dropbox"></i> Usługi</li>
<li><i class="fa fa-user"></i> Realizacje</li>
<li><i class="fa fa-user"></i> Etapy </li>
<li><i class="fa fa-stack-exchange"></i> O nas</li>
<li><i class="fa fa-whatsapp"></i> Kontakt</li>
</ul>
</div>
<!-- <div class="social-media hidden-sm hidden-xs">
<ul class="nav navbar-nav">
<li>
<i class="fa fa-facebook"></i>
</li>
</ul>
</div> -->
</div>
</div>
</nav>
You don't need the wrapping div#bs-example-navbar-collapse-1s for a navbar to work.
And wrap a link tag around the image to redirect it to your homepage.
Update:
Issue 1) There are limitations to how many items Bootstrap can show in a navigation bar. Please check the docs and read the limitations.
Issue 2) I have fixed the code. Please ensure that jQuery and bootstrap JS files are loaded.
Issue 3) I cannot recreate the issue. It seems related to the logo size. Can you post a jsFiddle?
Updated Here is the fixed code:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<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="//www.your-any-webste.com/"><img src="img/ico2.png" class="img-responsive" alt="logo"></a>
</div>
<ul class="nav navbar-nav collapse navbar-collapse text-center" id="bs-example-navbar-collapse-1">
<li><i class="fa fa-windows"></i> Witamy</li>
<li><i class="fa fa-dropbox"></i> Usługi</li>
<li><i class="fa fa-user"></i> Realizacje</li>
<li><i class="fa fa-user"></i> Etapy </li>
<li><i class="fa fa-stack-exchange"></i> O nas</li>
<li><i class="fa fa-whatsapp"></i> Kontakt</li>
</ul>
</div>
</nav>

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>

Moving navbar below header bootstrap

I am quite new to bootstrap and I was wondering if anyone could give some advice as to how I would be able to place my navbar underneath my header. This is my current code for the two:
Header:
<div class="row">
<div class="col-lg-12">
<div class="intro-message">
<h1>HOST</h1>
<h3>two is better than one</h3>
<hr class="intro-divider">
<ul class="list-inline intro-social-buttons">
<li>
<i class="fa fa-twitter fa-fw"></i> <span class="network-name">Twitter</span>
</li>
<li>
<i class="fa fa-github fa-fw"></i> <span class="network-name">Github</span>
</li>
<li>
<i class="fa fa-linkedin fa-fw"></i> <span class="network-name">Linkedin</span>
</li>
</ul>
</div>
</div>
</div>
</div>
Navbar:
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
<div class="container topnav">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-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>
<a class="navbar-brand topnav" href="/">Host</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
Login
</li>
<li>
Sign up
</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Any kind suggestions and tips would be greatly appreciated. I am also fairly new to programming so good explanations go along way! =)
Just change
navbar-fixed-top
to
navbar-top
Edit for the second answer:
Change your to
<nav id="myNav" class="navbar navbar-default" role="navigation">
And you will need to add jquery reference and this little script.
var headerHeight = 200;
$(window).bind('scroll', function () {
if ($(window).scrollTop() > headerHeight) {
$('#myNav').removeClass('navbar-top');
$('#myNav').addClass('navbar-fixed-top');
} else {
$('#myNav').removeClass('navbar-fixed-top');
$('#myNav').addClass('navbar-top');
}
});
Basically what this does is checks how much you have scrolled from top and when you pass your header height it fixes the nav to stay on top. You just need to change the headerHeight value to your header height.
<!DOCTYPE html>
<html >
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<style>
.navbar-fixed-top{
position:static;
}
</style>
</head>
<body>
<div class="row">
<div class="col-lg-12">
<div class="intro-message">
<h1>HOST</h1>
<h3>two is better than one</h3>
<hr class="intro-divider">
<ul class="list-inline intro-social-buttons">
<li>
<i class="fa fa-twitter fa-fw"></i> <span class="network-name">Twitter</span>
</li>
<li>
<i class="fa fa-github fa-fw"></i> <span class="network-name">Github</span>
</li>
<li>
<i class="fa fa-linkedin fa-fw"></i> <span class="network-name">Linkedin</span>
</li>
</ul>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
<div class="container topnav">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-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>
<a class="navbar-brand topnav" href="/">Host</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
Login
</li>
<li>
Sign up
</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
</body>
</html>