Bootstrap navbar-fixed-top is not working - css

I am trying to create a page with a fixed navigation bar at the top of the page. What I need is something like this.
As we can see in above linked page, the content of the page starts after giving priority to the navbar. But in my case, the content starts right from the beginning of the page. It is like the navbar is placed on top of the other content.
You can see the JsFiddle demo here.
In the demo page, I have not added anything new. It contains the source of the page which is linked earlier in this question.
this is my navbar and the other div which have been put inside the body section of the page.
<!-- Fixed navbar -->
<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">
.......
</button>
<a class="navbar-brand" href="#">Bootstrap theme</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
.......
</ul>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>
<div class="container theme-showcase" role="main">
.....
</div>
Why can't I see my page as needed. Have I missed something in my code?

In the Bootstrap template they have this css code
body {
padding-top: 70px;
padding-bottom: 30px;
}
and this code is used in theme.css file which is not included in your html.
You can resolve this by adding only the code above in your CSS code
or you can link to theme.css file in your HTML code

Add CSS:
body {
padding-top: 70px;
}
You can see this by inspecting the element here. It do exist in css.
https://getbootstrap.com/examples/navbar-fixed-top/

Related

add a tall image to a bootstrap navbar

I've got a nasty little problem I can't solve. I need to add an tall image to a bootstrap navbar (navbar-fixed-top, if possible). The image is in the navbar-brand. Let's say that the image is 350px high, and the navbar 60px. That causes the background of the navbar to fill the space to the bottom of the image.
I need that image to stick out of the navbar and to have to text under it flow around it. If I use an absolute position for the image, it will be where I want it, but it will lay on top of the text. That's not good. I need the text to float around it.
How do I solve this one?
Not sure if this is what you're looking for, or why you'd want to do this exactly, but this is my take on it:
I'd put the image in the body of the page, unless there's good reason to leave it in the header? This allows you to set properties for the surrounding text more effectively.
One note - the image you're using is a complete raster image, therefore, text won't wrap around the exterior of it like print layout will in an inline image in a magazine or newspaper for example. So if that's what you're looking for, you'd need to start with different image assets.
I chose to address this question as if you wanted the text to wrap around the image rectangle only.
Also, I abandoned your css, and commented out two calls in the body to js files I didn't have locally, so that could impact the outcome.
Final note - because this image overlaps the header, I'd recommend doing something like a "pull-right" on the navbar so it doesn't get overlapped by the logo image.
The following HTML should be all you need to see the results - I'm just grabbing jQuery and Bootstrap from CDNs, should work for you as well. Let me know if you have any questions on it.
<!DOCTYPE HTML>
<html>
<head>
<title>
</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<style>
.navbar-brand {
position: relative;
top: -130px;
left: -60px;
margin: 0 0 25px 0;
padding: 0;
height: auto;
}
</style>
</head>
<body>
<div class="container">
<!-- Static navbar -->
<nav class="navbar navbar-default">
<div class="container">
<div class="row">
<div class="col-xs-9 pull-right">
<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="https://www.bitballoon.com//images/posts/grunt-logo.png"></a> -->
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active">Default <span class="sr-only">(current)</span></li>
<li>Static top</li>
<li>Fixed top</li>
</ul>
</div>
<!--/.nav-collapse -->
</div><!-- col-xs-8 -->
</div><!-- row -->
</div>
<!--/.container-fluid -->
</nav>
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<a class="navbar-brand" href="#"><img src="https://www.bitballoon.com//images/posts/grunt-logo.png"></a>
<h1>Navbar example</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>
<a class="btn btn-lg btn-primary" href="../../components/#navbar" role="button">View navbar docs »</a>
</p>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script>
window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- not sure what this is... removing ..................
<script src="js/docs.min.js"></script> -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug
..... don't have this script, removing .................
<script src="js/ie10-viewport-bug-workaround.js"></script>
-->
</body>
</html>

Bootstrap nav toggle without navbar element

Is it possible to create the toggle button without using all the markup for default navigation?
I just want to create simple menu with the collapse feature. For example:
<div class="navigation">
<ul id="nav-to-collapse">
<li></li>
<li></li>
<li></li>
</ul>
<a href="#" class="toggle" data-toggle="collapse" data-target="#nav-to-collapse">
</div>
Would this be possible? Its my first time using Bootstrap (3) and Its really confusing. I dont want to use all the navbar classes because then I would have to overwrite all the navbar styles just to create simple menu that I want.
EDIT: I managed to create the toggle without all the useless navbar classes but there is an issue with the toggle animation, when nav height is changed. Here is a jsfiddle to ilustrate the problem: Jsfiddle demo
Bootstrap's toggle function is a javascript function that is triggered when the user clicks the element with an attribute of data-toggle="collapse". If there is not also a data-target="" id specified, then the element that the user clicks is collapsed. However, in this bit of markup:
<a href="#" class="toggle" data-toggle="collapse" data-target="#nav-to-collapse">
The data-target="" attribute is set to the id of #nav-to-collapse. So Bootstrap's collapse plugin is going to look for an id="nav-to-collapse" and trigger its function on that id.
So in this markup:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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 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>
</div>
The data-target is set to the class of .navbar-collapse, which will make everything underneath that element collapse.
Fixed the collapse animation issue by using min-height instead of height on the nav element. Here is a fiddle: http://jsfiddle.net/cfcZY/2/
nav { min-height: 100px; }

Bootstrap 3 Full-width Jumbotron outside container after <header>

Starting out with Bootstrap 3 and just getting used to it.
I've copied the navbar from the Bootstrap 3 docs becuase it has the exact functionality that I want and why invent the wheel hey.
I want to put a Jumbotron after the header but I want it to be full width, so according to the docs I don't enclose it in a container div.
The problem is that when I omit the container div it slides back under the header but I want it to start where the header ends. If I put it inside a container it sits nicely under it.
Can someone show me where I'm going wrong and how to fix it without making some hack div that pushes it down. Many thanks.
I want to keep the container in the header tag becuase I don't want these elements stretching to the sides.
<!-- Docs master nav -->
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-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="imagenes/logo.png" />
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav navbar-right pull-down">
<li class="">
Menu
</li>
<li class="">
Galería
</li>
<li class="">
Calendario
</li>
<li class="">
BH Musicos / Talentos
</li>
<li class="">
Blog
</li>
<li class="">
Contacto
</li>
</ul>
</nav>
</div>
</header>
<div class="jumbotron">
<h1>Hello World</h1>
<p>Testing one two three</p>
</div>
If you look at the "Fixed to top" section on the navbar docs, there's an alert urging you to add padding to the body:
Body padding required
The fixed navbar will overlay your other content, unless you add
padding to the top of the <body>. Try out your own values or use our
snippet below. Tip: By default, the navbar is 50px high.
body { padding-top: 70px; }
Make sure to include this after the core
Bootstrap CSS.
Adding a container inside the jumbotron will also fix this.

Bootstrap 3.0 Navbar Center

Im in the middle of migrating my project form Bootstrap 2.3.2 to Bootstrap 3.
I am unable to center the navbar links as I was able to before. I used this method previously: Center bootstrap's brand and list items but is not working for my new navbar.
The below link is a jsfiddle direclty using one of bootstraps examples (with the sticky footer and navbar)
Can someone please help me center these links?
http://jsfiddle.net/brainbolt/52VtD/4/
HTML
<div class="navbar navbar-default navbar-fixed-top center">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <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">
<li>About
</li>
<li>Services & Promos
</li>
<li>Contact
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
CSS
.navbar-default > .container { text-align: center }
Thanks!
Refer this site, Paste your bootstrap 2.3.2 code in here, and click button showing 2.x>3.
This will migrate your code automatically to 3.0.
OR
Refer this, to get bootstrap documentation for migration.
Hope this helps.

Change Bootstrap 2.0.4 responsive navbar width

I'm creating a Site using Twitter Bootstrap 2.0.4 + bootstraps responsive.css. What I don't know is: Is it possible to have a logo appearing at the top left of the site and the navbar appearing on the right of the logo (but fixed at top)? While changing Sizes, the Logo should then appear on top of the navbar.
Would be really nice to get an answer for I haven't found anything helpful yet.
Greetings,
Dominik
edit: Here's a picture describing what I want to achieve: http://i.imgur.com/HX3ZM.png
Logo on the left, then navbar.
Okay, I got it. I used the fixed navbar, which didn't work as expected. You have to use a static navbar. Then you could just use the row / scaffolding system from bootstrap.
Example code for a logo left from the navbar:
<div class="row-fluid">
<div class="span3">
<p><img src="/sites/img/your_logo.png" alt="Logo" class="responsive-logo"></p>
</div>
<div class="span9">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="btn-group pull-right">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-user"></i> Username
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Profile</li>
<li class="divider"></li>
<li>Sign Out</li>
</ul>
</div>
<div class="nav-collapse">
<ul class="nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
</div><!-- end navbar -->
</div><!-- end span8 -->
</div><!-- end row -->
To make my Logo responsive, I added the following css rules:
.responsive-logo {
max-width: 100%;
height: auto;
border: 0;
padding-top: 10px;
}
Yes, sure—you will need to re-structure your document to place (for example) a div with the span4 class above the navbar.
Below that, have the navbar code and remove the branding elements (which usually house your logo). My assumption leads me to believe you want something like this:
If you can be a bit more specific about what you want, and/or provide the relevant parts (HTML) of your site, I can likely give some more direction.

Resources