Having trouble with fixed navbar not getting parrent width? - twitter-bootstrap-3

I've recently started working with bootstrap and is somewhat a newbie to webdesign as well.
I've been having trouble with my navbar not enheriting the .container-fluid width, which in the end making in non-responsive. I wanted my navbar to be fixed and in "high" z-position, to overlap content. I've been searching far and low on Stack Overflow to find an answer but with no luck. Can some wiz please enlighten me?
I don't have the exact code currently but it look something like:
<div class="container-fluid">
<div class="navbar">
<ul class="nav nav-pills" id="navbar">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
CSS
#navbar{
position:fixed;
z-index:999;
background-color: rgba(0,0,0,0.7);
}

There is a CSS Class(navbar-fixed-top) in bootstrap for a fixed navbar.
Change your first <div> to <nav> (nav is a div but it is the HTML5 standard)
Add the navbar-default & navbar-fixed-top to your <nav>
Nest your container-fluid div inside your <nav>...</nav>
Add link tags to your <li> items
HTML:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<ul class="nav nav-pills" id="navbar">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
</nav>
Then you will need to add padding to your body in your CSS file if you dont want the navbar to overlap content:
CSS:
body{
padding-top: 70px;
}
Documentation here
I hope this helps!

Related

Bootstrap 3 navbar over first row

I have had a search and cannot find this exact problem so I hope the question is not duplicate.
First time users of Bootstrap 3.
From reading here and the bootstrap documentation I believe the navbar should have its own container such as:
<nav id="myNavbar" class="navbar navbar-default 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="#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="/index.html">My Site</a>
</div>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="nav navbar-nav">
<li class="active"><span class="glyphicon glyphicon-home"></span> Home</li>
<li><span class="glyphicon glyphicon-list-alt"></span> Services</li>
<li><span class="glyphicon glyphicon-info-sign"></span> About</li>
<li><span class="glyphicon glyphicon-envelope"></span> Contact</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">content goes here and this content is under the navbar</div>
</div>
The body of the page then has its own container. Is that Correct?
I have done that and then added a row but the first row content is under the navbar.
Have I missed something like a class that I should add to the first row to ensure it starts below the navbar and not after it?
I found a similar question where the answer was to ensure the navbar had "navbar-fixed-top" but I already have that.
Read documentation carefully.
According to Bootstrap navbar docs:
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; // Your navbar height
}
Make sure to include this after the core Bootstrap CSS.
If I understand your problem correctly that you want content below the navbar just write
navbar-fixed
instead of
navbar-fixed-top
like this
<nav id="myNavbar" class="navbar navbar-default navbar-inverse navbar-
fixed"role="navigation">
it will work
see this fiddle fiddle
are you looking for this ???
This is caused by the Bootstrap class fixed-top, Fixed navbars use position: fixed, which pulls the Nav from the normal flow of the DOM.
For this to have an effect, having your content below the Navbar not overflow unto the Navbar, BootStrap Docs>> https://getbootstrap.com/docs/4.5/components/navbar/
Under the #Placement section, advise you to give custom CSS to the body.
Add some padding to the <body style="padding: somepadding"> element.

Issue with Bootstrap 3 media mobile display of navbar

I'm trying to figure out why my changes to the padding and margin properties of the various navbar assets is failing to allow for the menu to resize properly on mobile.
JsFiddle is at https://jsfiddle.net/phobrla/b9zpbejg/
<html>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<!-- Collect the nav links, forms, and other content for toggling -->
<ul class="nav navbar-nav">
<li>The Burkean<br/>Pentad</li>
<li class="active">Intro <span class="sr-only">(current)</span> </li>
<li>Act</li>
<li>Scene</li>
<li>Agent</li>
<li>Agency</li>
<li>Purpose</li>
<li>Quiz</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
</html>
Chande .navbar-inverse by .navbar-default
Regards!
JSFIDDLE
.navbar-outer .navbar-default{
background:red;
}
<div class="navbar-outer">
<nav class="navbar navbar-default">

Image is not responsive with class added

as the title says. Here is the code I'm using this theme http://startbootstrap.com/template-overviews/grayscale/
Edit where is the whole code to make it clear:
<nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-collapse">
<i class="fa fa-bars"></i>
</button>
<a class="navbar-brand page-scroll" href="#page-top">
<!-- <i class="fa fa-play-circle"></i> <span class="light">Start</span> Bootstrap -->
<img class="img-responsive" src="img/ssmk_logo.png">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-right navbar-main-collapse">
<ul class="nav navbar-nav">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
</li>
<li>
<a class="page-scroll" href="#weather">Weather Forecast</a>
</li>
<li>
<a class="page-scroll" href="#download">Estate Agent</a>
</li>
<li>
<a class="page-scroll" href="#contact">Stocks</a>
</li>
<li>
<a class="page-scroll" href="#about">About Us</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Should the objective be to get your logo into the Bootstrap navbar, you'll have to resize the image in some way. Your options for that are to do it with CSS, or to make a smaller version of it to be served up to your site. My solution resizes it using CSS.
img {
margin-top: -11px;
height: 40px;
width: 45px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img alt="Brand" src="http://i.imgur.com/9PRm767.png" />
</a>
</div>
</div>
</nav>
Per the documentation for Bootstrap nav branding using images, this is how you add an image to your navbar instead of text for branding purposes. The documentation also says you'll need to either override some CSS depending on your image. My CSS here gets rid of some of the margin the navbar-header creates so the image is nice and flush with the rest of the navbar. Should you want a larger image to be used, you'll need to mess with the width of your navbar.
Using the img-responsive class from Bootstrap is not appropriate here due to the widths of various components in the navbar for Bootstrap, which only collapses down in smaller viewports and does not, itself, dynamically resize along all dimensions as the viewport gets wider. The Bootstrap navbar is easily the most inflexible item in the entire framework, but that's not a bad thing because really, you shouldn't be messing with the size of the navbar too much.
UPDATE
With the correct closing tags that should work. As you can see if you resize Maradona image, it appears to be responsive. I suggest you to validate your entire HTML and check if there is some error on it.
http://jsfiddle.net/xd1p8pov/
Your html (as we see it) is missing one div and one nav closing tags. Have you tried to inspect the .img-responsive class? By default in Bootstrap should be :
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}

bootstrap 3 tabs not working properly

I almost copied the code from their website. The tab is initiated perfectly, and when I click on tabs, new panels are activated. However, the "active" class is not applied to the activated tab.
This is the code:
<ul class="nav nav-tabs">
<li data-toggle="tab" data-target="#a" class="active">a</li>
<li data-toggle="tab" data-target="#b" >b</li>
<li data-toggle="tab" data-target="#c" >c</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="a"> in tab a </div>
<div class="tab-pane fade" id="b">in tab b</div>
<div class="tab-pane fade" id="c">in tab c</div>
</div>
According to the Docs you need to put an id on each link in the header and that link needs to be inside the li which should have no other styles, i.e doesn't need all the data-target stuff in the li. Your list has with no data-toggle or id.
Your HTML would be like this
<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.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="nav nav-tabs">
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="a">AAA</div>
<div class="tab-pane" id="b">BBB</div>
<div class="tab-pane" id="c">CCC</div>
<div class="tab-pane" id="d">DDD</div>
</div>
And you shouldn't need any Javascript, according to the Docs
Make sure your jquery is inserted BEFORE bootstrap js file:
<script src="jquery.min.js" type="text/javascript"></script>
<link href="bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script src="bootstrap.min.js" type="text/javascript"></script>
In my case, I have two elements with the same id. I could not notice the cause of problem for a long time, because the first such element was hidden.
This will work
$(".nav-tabs a").click(function(){
$(this).tab('show');
});
My problem was that I sillily concluded bootstrap documentation is the latest one.
If you are using Bootstrap 4, the necessary working tab markub is: http://v4-alpha.getbootstrap.com/components/navs/#javascript-behavior
<ul>
<li class="nav-item"><a class="active" href="#a" data-toggle="tab">a</a></li>
<li class="nav-item">b</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="a">a</div>
<div class="tab-pane" id="b">b</div>
</div>
My problem was with extra </div> tag inside the first tab.
for some weird reason bootstrap tabs were not working for me until i was using href like:-
<li class="nav-item"><a class="nav-link" href="#a" data-toggle="tab">First</a></li>
but it started working as soon as i replaced href with data-target like:-
<li class="nav-item"><a class="nav-link" data-target="#a" data-toggle="tab">First</a></li>
In my case we were setting the div id as a number and setting the href="#123", this did not work.. adding a prefix to the id helped.
Example:
This did not work-
<li> <a data-toggle="tab" href="##i"> <li/>
...
<div class="tab-pane" id="##i">
This worked:
<li><a data-toggle="tab" href="#prefix#i"><li/>
...
<div class="tab-pane" id="#prefix#i">
One more thing to check for this issue is html tag attribute id. You should check any other html tags in that page have the same id as nav tab id.
When I removed the smooth scroll script (https://github.com/cferdinandi/smooth-scroll), it worked.
When I moved the following lines from the head section to the end of the body section it worked.
<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.7/js/bootstrap.min.js"></script>
In my case (dynamically generating the sections): the issue was a missing "#" in href="#...".
For anyone struggling with this issue using bootstrap3 use the below classlist. If you've copy pasted from the DOC, It won't surely work. Becasue of the .show in new version.
<div class="tab-pane fade in active" >
<div class="tab-pane fade in" >
Use this for your code
<ul class="nav nav-tabs" style="margin-top:10em;">
<li class="active" data-toggle="tab">Assign</li>
<li data-toggle="tab">Two</li>
<li data-toggle="tab">Three</li>

How can I place a div below a navbar

I need to place a div below my top navbar which should not scroll with the page content just like the navbar.
I've tried to create it as a second navbar but it is still scrolling or causing a blank area above the two navbars.
How can I do this?
UPDATE
In this sample the green bar is on top of the navbar, but I need it to stay below the navbar: http://jsfiddle.net/julianonunes/y8YqK/
If I move the green bar code (code sample below) before the navbar, it is hidden by the navbar.
Ex:
<div class="navbar navbar-decoration navbar-fixed-top"></div>
<div class="navbar navbar-default navbar-remote navbar-fixed-top">
<div class="navbar-header"> Brand
</div>
</div>
Ok. The problem is your second div includes 'navbar-fixed-top' which is glueing it to the top of your screen. You don't want it fixed to the top - you just want it fixed in place below the main navbar. Change your html for the second nag to:
<div class="navbar navbar-default navbar-remote navbar-decoration ">
And add to your navbar-decoration class:
width: 100%
position: fixed;
You may have tried this already, but in the css for the second navbar put
position: fixed;
If you don't want to add to your stylesheet, you can put it in the div like this:
<div style="position: fixed;"> </div>
I am not sure, but you may also have to add display:block like this:
<div style="position: fixed; display: block;"> </div>
With Bootstrap, use this logic within their html/css:
<div class="navbar" style="position: fixed; display: block;">
<div class="navbar-inner">
<a class="brand" href="#">Title</a>
<ul class="nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
My last guess:
<div class="navbar" style="margin-top: 10px;">
<div class="navbar-inner">
<a class="brand" href="#">Title</a>
<ul class="nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
Hope one of those works.
I've got it fixed by adding margin-top to the second navbar with navbar-fixed-top.
<div class="navbar navbar-default navbar-remote navbar-fixed-top">
<div class="navbar-header"> Brand
</div>
</div>
<div class="navbar navbar-decoration navbar-fixed-top"></div>
CSS
.navbar-decoration {
margin-top: 50px;
min-height: 5px;
max-height: 5px;
/* ... */
}