Responsive bootstrap nav with brand - html

I'm having trouble keeping my navbar responsive. When the browser reaches a certain size, the height will increase. I made a fiddle to show what is happening, if you expand the preview, the navbar will be normal.
http://jsfiddle.net/x70r23cn/
.navbar {
background-color: #204489;
box-shadow: 0 4px 8px rgba(0,0,0,.25);
float: center;
}
.navbar a {
color: #fff;
}
.navbar-brand img {
margin-left: auto;
margin-right: auto;
height: 25px;
}
.navbar-brand {
margin-left: auto !important;
margin-right: auto !important;
display: block !important;
float: none !important;
}
<nav class='navbar navbar-fixed-top'>
<div class='container'>
<div class='navbar-header'>
<button aria-controls='navbar' aria-expanded='false' class='navbar-toggle collapsed' data-target='#navbar' data-toggle='collapse' type='button'>
<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='navbar-brand'>
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=271&h=25" />
</div>
</div>
</nav>

Remove the navbar-header class as it's designed to enable the collapse menu on mobile devices; that's why the navbar is expanding.
See example Snippet.
.navbar.navbar-custom {
background-color: #204489;
box-shadow: 0 4px 8px rgba(0, 0, 0, .25);
float: center;
}
.navbar.navbar-custom a {
color: #fff;
}
.navbar.navbar-custom .navbar-brand {
margin-left: auto;
margin-right: auto;
display: block;
float: none;
}
.navbar.navbar-custom .navbar-brand img {
margin-left: auto;
margin-right: auto;
height: 25px;
margin-top: -2px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class='navbar navbar-custom navbar-fixed-top'>
<div class='container'>
<div class='navbar-brand'>
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=271&h=25" />
</div>
</div>
</nav>

try this... the navbar-brand needs to be in the navbar-header and the navbar-brand needs to be inline or inline-block.
.navbar {
background-color: #204489;
box-shadow: 0 4px 8px rgba(0,0,0,.25);
float: center;
}
.navbar a {
color: #fff;
}
.navbar-brand img {
margin-left: auto;
margin-right: auto;
height: 25px;
}
.navbar-brand {
margin-left: auto !important;
margin-right: auto !important;
display: block !important;
float: none !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<nav class="navbar navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button aria-controls="navbar" aria-expanded="false" class="navbar-toggle collapsed" data-target="#navbar" data-toggle="collapse" type="button">
<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">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=271&h=25" />
</a>
</div>
</div>
<nav>

Related

Bootstrap navbar collapse opens in the wrong place

Navbar collapsed menu fits perfectly to the navbar in Safari browser and occupy full width of the viewport. However, in other browsers collapsed navbar is getting smaller and sticks to the very top of the page. Looks like it is not connected to the navbar itself and drops down from another reference point. Is this a browser prefix issue or something entirely wrong with my bootstrap structure?
.navbar {
height: 60px;
padding: 0;
margin: 0;
border-bottom: .1px solid black;
background: #ffffff;
}
.navbar-nav {
margin-top: 1.5em;
}
.navBut {
margin: 20px 0;
}
.navButBut {
border: 1px solid red;
}
.navbar-toggle {
border-color: black !important;
color: snow;
height: 30px;
width: 45px;
padding: 2px 5px 0;
margin: 15px 8% 15px 0;
}
.navbar-toggle:hover {
background-color: transparent !important;
}
.dropbut {
font-size: 1.5em;
color: black;
}
.fa-korvue {
color: #962715;
font-size: 3.5em;
line-height: -45%;
float: left;
margin: 5px 8% 0 12%;
}
.link_icon, .link_icon:link, .link_icon:visited, .link_icon:active {
color: #1e1e20;
padding: 0;
margin-right: 20px;
font-family: 'Arsenal', sans-serif;
font-size: 1.2em;
text-decoration: none;
outline: 0;
cursor: pointer;
background: transparent;
}
#collapse_menu {
margin-top: 1.2em;
}
#collapse_menu li a {
padding: 3px 8px;
margin-right: 5px;
border-radius: 3px;
}
#collapse_menu li a:hover {
background-color: rgba(0, 0, 0, 0.2) !important;
}
.hidden-xs {
margin-right: 18px;
}
#phone_handset {
color: black;
font-size: 1.7em;
vertical-align: 10%;
text-decoration: none;
outline: 0;
transition: 1s;
}
#phone_num {
display: inline;
margin-right: 4em;
vertical-align: 20%;
font-size: 1.3em;
}
<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.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<header>
<nav class="navbar navbar-fixed-top">
<div class="container-fluid">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="fa fa-th dropbut"></span>
</button>
<i class="fab fa-korvue"></i>
<div class="collapse navbar-collapse" id="myNavbar">
<ul id="collapse_menu" class="nav navbar-nav text-center">
<li><a class="link_icon scroll" name="1" href="#top_page_scroll">Начало</a></li>
<li><a class="link_icon scroll" name="2" href="#about_me_scroll">Обо мне</a></li>
<li><a class="link_icon scroll" name="3" href="#portfolio_scroll">Услуги</a></li>
<li><a class="link_icon scroll" name="4" href="#pricing_scroll">Цены</a></li>
<li><a class="link_icon scroll" name="5" href="#contact_me_scroll">Регистрация</a></li>
</ul>
<div class="navbar-nav navbar-right vertical-align">
<a id="phone_handset" class="fas fa-phone-volume hidden-xs" href="#"></a>
<a id="phone_num" class="link_icon hidden-xs" href="#">110-223-456-78</a>
</div>
</div>
</div>
</nav>
</header>
I finally fixed this issue. If you wrap navbar-toggle with <div class=“navbar-header”> then everything starts to work as expected. Now collapsed navbar occupies full width and sits in the right place. Thank #fnostro for the valuable tips.
<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.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<header>
<nav class="navbar navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="fa fa-th dropbut"></span>
</button>
<i class="fab fa-korvue"></i>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul id="collapse_menu" class="nav navbar-nav text-center">
<li><a class="link_icon scroll" name="1" href="#top_page_scroll">Начало</a></li>
<li><a class="link_icon scroll" name="2" href="#about_me_scroll">Обо мне</a></li>
<li><a class="link_icon scroll" name="3" href="#portfolio_scroll">Услуги</a></li>
<li><a class="link_icon scroll" name="4" href="#pricing_scroll">Цены</a></li>
<li><a class="link_icon scroll" name="5" href="#contact_me_scroll">Регистрация</a></li>
</ul>
<div class="navbar-nav navbar-right vertical-align">
<a id="phone_handset" class="fas fa-phone-volume hidden-xs" href="#"></a>
<a id="phone_num" class="link_icon hidden-xs" href="#">110-223-456-78</a>
</div>
</div>
</div>
</nav>
</header>

how to align logo and header title on same line in a responsive site

I am trying to align a header title and logo in same line.
On desktop and laptop it looks great but on mobile the logo overlap the title that you won't see all the text clearly.
Below here are my code.
.page-header {
margin: 10px 0;
padding: 10px 0;
width: 100%;
height: 224px;
display: block;
position: relative;
}
.page-header #title {
text-align: left;
font-size: 40px;
float: left;
}
.page-header #logo {
height: 60px;
width: 100px;
float: right;
right: 0;
bottom: 0;
position: absolute;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<header class="page-header">
<div class="navbar navbar-default navbar-fix-top" role="Navigation">
<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>
<img src="images/dove.png" id="logo">
<div id="title">Birdwatching</div>
</div>
</div>
</div>
</header>
You should not use absolute positioning if you don't want overlapping. Also you can use here flexbox approach, so you can remove your floats here and move elements in more natural order in HTML. Demo:
header .navbar-header {
/* become a flex-container */
/* its immediate children will be flex-items */
display: flex;
/* doing some normalising due to default bootstrap styles */
width: 100%;
margin: 0 !important;
padding: 0 15px;
}
.navbar-header > a {
/* move to the right */
margin-left: auto;
}
.navbar-header > button {
margin-left: 5px;
}
.page-header {
margin: 10px 0;
padding: 10px 0;
width: 100%;
height: 224px;
display: block;
}
.page-header #title {
text-align: left;
font-size: 40px;
}
.page-header #logo {
height: 60px;
width: 100px;
}
<link rel="stylesheet" href=" https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<header class="page-header">
<div class="navbar navbar-default navbar-fix-top" role="Navigation">
<div class="container">
<div class="navbar-header">
<div id="title">Birdwatching</div>
<img src="images/dove.png" id="logo">
<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>
</div>
</div>
</div>
</header>

navbar from left side to top using bootstrap 3

I've been having a hard time getting the hamburger menu to work onnce the screen size decreases to anything below 1200px. How can I get my list items to show up below my top nav bar?
This is what I have so far:
.mainBackground {
background-image: url('https://res.cloudinary.com/knaguibimages/image/upload/o_65/v1474765365/Background_p3qqpv.jpg');
background-repeat: no-repeat;
background-size: cover;
position: relative;
}
#media screen and (min-width: 1200px) {
.body-wrapper {
padding-left: 80px;
}
}
#media screen and (min-width: 1200px) {
.navbar {
width: 80px;
max-width: 80px;
position: fixed;
top: 0;
left: 0;
height: 100%;
border: 0;
border-radius: 0;
text-align: center;
}
}
.navbar {
z-index: 10000;
background: rgba(30, 30, 31, 0.85);
}
#media screen and (max-width: 1200px) {
.navbar-header {
float: left;
padding: 0 40px;
}
}
.navbar-brand {
padding: 50px 0 50px 25px;
float: left;
height: auto;
}
#media screen and (min-width: 1200px) {
.navbar-brand {
position: relative;
box-shadow: none;
margin: 12px 0;
}
}
ul li a span {
display: inline-block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}
.btn.responsive-menu {
display: none;
}
#media screen and (max-width: 1200px) {
.btn.responsive-menu {
margin: 45px 50px 0 0;
display: inline-block;
float: right;
}
}
.btn {
color: #0067b5;
background: none;
border: 2px solid;
-webkit-transition: all 200ms ease-in;
}
.current {
color: white;
}
section {
padding-top: 50px;
padding-left: 50px;
padding-right: 70px;
margin-bottom: 106px;
}
section .box {
padding: 50px;
background-color: rgba(0, 0, 0, 0.75);
}
.section-title {
margin-bottom: 20px;
font-size: 22px;
line-height: 28px;
color: white;
}
#aboutMe-responsive {
display: none;
}
#myPortfolio-responsive {
display: none;
}
#contactMe-responsive {
display: none;
}
#aboutMe {
padding: 0 50px 20px 0;
}
#myPortfolio {
padding: 0 50px 20px 0;
}
#contactMe {
padding: 0 50px 20px 0;
}
#media screen and (max-width: 1200px) {
#aboutMe {
display: none;
}
#myPortfolio {
display: none;
}
#contactMe {
display: none;
}
#aboutMe-responsive {
display: inline;
}
#myPortfolio-responsive {
display: inline;
}
#contactMe-responsive {
display: inline;
}
}
.frame {
position: relative;
border: 4px solid;
border-color: rgba(0, 0, 0, 0.5);
overflow: hidden;
margin: 0 0 15px 0;
}
p {
font-size: 15px;
line-height: 30px;
letter-spacing: 0.3px;
color: white;
}
<!--Navigation- Bar-->
<nav class="navbar navbar-default" role="navigation">
<!--Navbar header-->
<div class="navbar-header">
<!-- Logo -->
<div class="navbar-brand text-center">
<!-- <a href="#"> -->
<i id="home" class="fa fa-home fa-2x"></i>
<!-- </a> -->
</div>
</div>
<!--Hamburger menu-->
<a class="btn responsive-menu" data-toggle="collapse" data-target=".navbar-collapse">
<i id="hamburger-menu" class="fa fa-bars fa-2x"></i>
</a>
<!--Navbar Icon Section Navigation-->
<!-- Add "in" when you want to collapse nav bar -->
<div id="nav-section-selection" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<!--About Me-->
<li>
<a href="#about">
<i id="aboutMe" class="fa fa-user fa-2x current"></i>
<span id="aboutMe-responsive">ABOUT ME</span>
</a>
</li>
<!--Portfolio-->
<li>
<a href="#portfolio">
<i id="myPortfolio" class="fa fa-briefcase fa-2x"></i>
<span id="myPortfolio-responsive">MY WORK</span>
</a>
</li>
<!--Contact-->
<li>
<a href="#contact">
<i id="contactMe" class="fa fa-envelope-o fa-2x"></i>
<span id="contactMe-responsive">CONTACT ME</span>
</a>
</li>
</ul>
</div>
</nav>
<!--Page Content Starts Here-->
<div id="pageContent">
<!-- About Me Section -->
<section id="about" class="about-section">
<div class="box">
<h2 class="section-title">A Little About Myself</h2>
<div class="row">
<div class="col-md-5 col-md-push-7">
<figure class="frame">
<img class="img-responsive about-me-img" src="https://res.cloudinary.com/knaguibimages/image/upload/v1474765942/ProfilePic_bvn1gs.jpg" alt="Karim Naguib Profile Picture">
</figure>
</div>
<div class="col-md-7 col-md-pull-5">
<p>Hello! My name's Karim Naguib, and this page was developed to showcase my coding talent.</p>
<p>I graduated from the University of Waterloo in 2015, with a degree in Management Engineering.</p>
</div>
</div>
</div>
</section>
<!-- Portfolio Section -->
<section id="portfolio" class="portfolio-section">
<div class="box">
<h2 class="section-title">My Work</h2>
</div>
</section>
<!-- Contact Section -->
<section id="contact" class="contact-section">
<div class="box">
<h2 class="section-title">Get In Touch With Me</h2>
</div>
</section>
</div>
</div>
<!-- Footer -->
</body>
</html>
you should try this inside your navbar-header class:
<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>

bootstrap css searchbox not fit in navigation bar

In my jsp page I want to put searchbox in the navigation bar items.
So I have done below code,click in the link(jsfiddle code).
jsfiddlecode link
But the problem is,search bar is not fit into the navigation bar itmes,when it is in mobile view. why it is not fit into the navigation bar??
You can place the button and the search form inside the navbar-header div so it won't become mixed in with the mobile navbar when the toggle button is clicked since it's currently included inside the nav links. Then you just need to adjust the placement of the toggle button.
*I also adjusted your navbar-nav since it's overlapping the search button at certain widths.
See working example Snippet.
$('#buttonsearch').click(function() {
$('#formsearch').slideToggle("fast", function() {
$('#content').toggleClass("moremargin");
});
$('#searchbox').focus()
$('.openclosesearch').toggle();
});
body {
padding-top: 70px;
}
.searchbardiv {
display: block;
position: fixed;
background: #7D1935;
top: 50px;
right: 0px;
width: 100%;
max-width: 100%;
padding: 10px;
margin: 0px;
}
#formsearch {
display: none;
}
.buttonsearch {
position: fixed;
color: white;
top: 15px;
right: 10px;
background-color: transparent;
border: 0px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.buttonsearch:hover {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border: 0px;
}
.buttonsearch:focus {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
outline: none;
border: 0px;
}
.glyphicon.glyphicon-search {
font-size: 18px;
}
#searchbox {
box-shadow: none;
padding: 8px 14px;
}
#searchbox:hover {
box-shadow: none;
}
.form-control:focus {
border-color: #ccc;
}
#media (min-width: 768px) {
.navbar .navbar-nav {
margin-right: 10px;
}
}
#media (max-width: 767px) {
.navbar .navbar-toggle {
margin-right: 50px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse 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">
<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="#">MyCompany</a>
<button type="button" class="buttonsearch" id="buttonsearch">
<i class="glyphicon glyphicon-search openclosesearch"></i>
<i class="glyphicon glyphicon-remove openclosesearch" style="display:none"></i>
</button>
<form role="search" method="get" class="searchbardiv" id="formsearch">
<div class="input-group">
<input type="text" id="searchbox" class="form-control" name="s" id="s">
<div class="input-group-btn">
<button class="btn btn-default" id="searchsubmit" type="submit">
<strong>Search</strong>
</button>
</div>
</div>
</form>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">
Home
</li>
<li>
link1
</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="well">
Content
</div>
</div>
You can write media css for phone ..just add
#media (max-width: 767px) {
#buttonsearch{
margin-right:20%;
}
}
It will do margin-right to Landscape phone , portrait tablet to phone

Making text appear next to icon

I want my "Navigation"text to appear just next to the icon, but I can't seem to be able to do it.
<nav class="nav-mobile">
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<div class="icon"><span class="icon-bar">
</span><span class="icon-bar">
</span><span class="icon-bar">
</span></div> <h3> Navigation</h3></a>
<div class="nav-collapse collapse" aria-expanded="false" style="height: 0px;">
</div></div></div></div>
</nav>
css
.icon-bar {
display: block;
width: 22px;
height: 2px;
border-radius: 1px;
background-color: #6c6d71;
}
nav .btn-navbar
{
display: block;
padding: 10px 15px;
border-top: solid 1px #d7d7d7;
border-bottom: solid 1px #d7d7d7;
}
https://jsfiddle.net/fLhrgw63/1/
Both H3 and the .icon div are block elements which will be 100% width by default. You need to change them to inline-block so that they are only as wide as the content within them.
.icon, h3 {
display:inline-block;
vertical-align:middle;
}
https://jsfiddle.net/fLhrgw63/3/
.icon and h3 are block elements. Making them inline-block should work:
CSS:
.icon {
display: inline-block;
width: 30px;
vertical-align: middle;
}
.nav-title {
display: inline-block;
}
HTML
<h3 class="nav-title">Navigation</h3>
.icon-bar {
display: block;
width: 22px;
height: 2px;
border-radius: 1px;
background-color: #6c6d71;
}
nav .btn-navbar {
display: block;
padding: 10px 15px;
border-top: solid 1px #d7d7d7;
border-bottom: solid 1px #d7d7d7;
}
.icon {
display: inline-block;
width: 30px;
vertical-align: middle;
}
.nav-title {
display: inline-block;
}
<nav class="nav-mobile">
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<div class="icon"><span class="icon-bar">
</span><span class="icon-bar">
</span><span class="icon-bar">
</span>
</div>
<h3 class="nav-title"> Navigation</h3>
</a>
<div class="nav-collapse collapse" aria-expanded="false" style="height: 0px;">
</div>
</div>
</div>
</div>
</nav>