On this bootstrap starter template:
when the browser gets narrow the navigation bar links/buttons collapse into one icon in top-right corner like this:
I would like to have this collapsed "icon" as default like on the picture above. So that the navbar links are available after the user clicks that top-right collapsed button.
How to do that?
This is the source code of the template:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<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="#">Project name</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="starter-template">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</div><!-- /.container -->
It's all in the CSS.
See this post and check out the css column.
Always Collapse Bootstrap Nav
Working Example:
.navbar .navbar-header {
float: none;
}
.navbar .navbar-toggle {
display: block;
}
.navbar .navbar-collapse.collapse {
display: none!important;
}
.navbar .navbar-nav {
float: none!important;
}
.navbar .navbar-nav > li {
float: none;
}
.navbar .navbar-collapse.collapse.in {
display: block !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.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-static-top">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav">
<li class="active">Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
</nav>
Related
I am using bootstrap 3.4.1 and I am having and issue with the navbar on phone (e.g. S9 )
The menu icon ends up going to new line. So I did col-xs-11 and col-xs-1 but still doesn't work. Here is the code:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="row">
<!-- THE MENU -->
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-11 col-xs-11">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">Hammad Muhammad Mehmood</a>
</div>
<div id="main-menu" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>Projects</li>
<li>Leetcode</li>
<li>About</li>
<li><span class="fa fa-github"></span>
</li>
</ul>
</div>
</div>
<!-- THE ICON -->
<div class="col-sm-1 col-xs-1">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu" 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>
</div>
</nav>
I have added this into my css so at least it shows in the new line , but it broke for other mobiles then. I don't know how to get it in the same line. Any help will be greatly appreciated:
.col-xs-1 {
width: 25%;
}
Firstly ditch the column constructs inside the bootstrap navbar. It was never intended for .row and .col- usage.
Because your .navbar-brand content is oversized for the S9 or any mobile device, it breaks the bootstrap mobile nav. Bootstrap 3 does not account for such oversized brand content. This is why flex is awesome in bootstrap 4.
Anyway with a few css tweeks (hacks) we can get the .navbar-brand content to break onto the next line, rather than the .navbar-toggle icon going to the next line.
See responsive example here... https://jsfiddle.net/joshmoto/k8c9uj7q/
.navbar-toggle {
position: absolute;
right: 0;
}
#media (max-width: 786px) {
.navbar-brand {
padding-right: 60px;
height: auto;
}
}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">Hammad Muhammad Mehmood</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu" 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 id="main-menu" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Projects</li>
<li>Leetcode</li>
<li>About</li>
<li><span class="fa fa-github"></span>
</li>
</ul>
</div>
</div>
</nav>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
I am customizing the Bootstrap navbar to be transparent and was able to force this using the !important tag on my css...
.navbar-default {
background-color: transparent !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<nav class="navbar transparent navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Meredith Bristol
</div>
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Contact Me</li>
<li>About Meredith</li>
<li>Employment History</li>
<li>Education</li>
</ul>
</div>
</div>
</nav>
However, I am now seeing a horizontal line/bar below the navbar itself, click here to see example. What is creating this line?
It's a border-bottom added by bootstrap, so you need to make its color transparent also (or remove it) :
/* only to show there is no more border/background on the navbar */
body {
background-color: lightblue!important;
}
/**/
.navbar-default {
background-color: transparent !important;
border-color: transparent !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<nav class="navbar transparent navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Meredith Bristol
</div>
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>Contact Me</li>
<li>About Meredith</li>
<li>Employment History</li>
<li>Education</li>
</ul>
</div>
</div>
</nav>
I would like to switch the brand and the toggle button in mobile view if the viewport is small enough. On desktop viewport the brand icons shall be on the right side and the links shall be displayed normaly.
Examples:
Desktop:
+--------------------------------------------+
|Link1 Link2 BrandIcon1 BrandIcon2 |
+--------------------------------------------+
Mobile:
+----------------------------+
|[=] BrandIcon1 BrandIcon2 |
+----------------------------+
What is the easiest and cleanest way to code this?
Made a Pen: http://codepen.io/Kaito23/pen/Wxmxgm
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
.navbar-toggle {
float:left;
}
.navbar-brand {
float: right;
}
<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" 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">
<ul class="nav navbar-nav navbar-left">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
</ul>
<ul class="visible-xs visible-xs visible-sm visible-md visible-lg nav navbar-nav navbar-right">
<li><img src="http://images.fatcow.com/icons/32/wordpress.png" /></li>
<li><img src="http://www.wbdesignideas.com/images_drf_color.png" /></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
Currently the problem is that when the icons are in the navbar-collapse class they disapear. If I put them under the collapse div, they are in a
new row.
Thanks in advance
Greetings
Kaito
Let's take Bootstrap's default navbar and remove unnecessary parts.
Then change floats to the opposite direction.
And add second brand before the first one. (It's because of the float: right; property.)
Please check the result: http://codepen.io/glebkema/pen/PzLbmz
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
#media (min-width: 768px) {
.navbar-header {
float: right;
}
}
.navbar-brand {
float: right;
}
.navbar-toggle {
float: left;
margin-left: 15px;
margin-right: 0;
}
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#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="#">Brand 2</a>
<a class="navbar-brand" href="#">Brand 1</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Left 1</li>
<li>Left 2</li>
<li>Left 3</li>
</ul>
</div>
</div>
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
Thank you for reading and answering my question. What I would like to do is have my links underlined once it is hovered. Without background color and with space between text. Sort of something like this using bootstrap. enter image description here
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Internship Exercise 1</title>
<link href="css/style.css" rel="stylesheet">
<link href="css/bootstrap.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body><!--Navbar start-->
<nav id="myNavbar" class="navbar navbar-default navbar-default navbar-static-top navpadding" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
<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="img/logo.jpg" alt="logo" width="90%"></a>
</div>
<div class="collapse navbar-collapse navmargin" id="navbarCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
<li>Pricing</li>
<li>Contact</li>
</ul>
</div>
</div>
With CSS here that have a temporary underline for active. How can I do this for hover? Looking forward to your answer. Thanks!
.navbar-default .navbar-nav > li > a {
color: #ffffff;
}
.underline {
border-bottom: solid 1px #ffffff;
display: inline;
padding-bottom: 2px;
}
Well that's why :hover exists :)
HTML:
<body><!--Navbar start-->
<nav id="myNavbar" class="navbar navbar-default navbar-default navbar-static-top navpadding" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
<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/2/24/Male_mallard_duck_2.jpg" alt="logo" height="100%"></a>
</div>
<div class="collapse navbar-collapse navmargin" id="navbarCollapse">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Pricing</li>
<li>Contact</li>
</ul>
</div>
</div>
</body>
CSS:
.navbar-default .navbar-nav > li > a {
color: #ffffff;
}
.navbar{
background:pink!important;
padding:10px;
}
.navbar li *:hover{
color:red!important;
}
.navbar li:hover{
border-bottom:3px solid white;
}
Here is a working fiddle: https://jsfiddle.net/dp17vjus/
I can't figure out how to put a brand logo into my bootstrap navbar. I want the logo to appear on the left side of the navbar and the links should be in the center.
https://jsfiddle.net/spon1r82/2/
In the jsfiddle example you can see, that the links are centered and the brand logo is in fact on the right site, but the logo and the links appear to be in two different rows. How do i move the logo in the same row as the links and still keep the same division (logo (left), links (centered))?
HTML
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<a class="navbar-brand" href="#">Brand Logo</a>
<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>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Stories</li>
<li>Videos</li>
<li>Photos</li>
</ul>
</div>
</div>
</nav>
CSS
/*NAVBAR*/
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
You could absolutely position it like this:
.navbar-brand{
position:absolute;
}
See this update fiddle.
Remove the width on .navbar-nav to get it working. See the example below.
EDIT I didn't see the comment by zgood, he has also the answer.
/*NAVBAR*/
.navbar-nav {
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" rel="stylesheet"/>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<a class="navbar-brand" href="#">Brand Logo</a>
<!-- 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>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Stories</li>
<li>Videos</li>
<li>Photos</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>