For some reason my navbar from using a bootstrap theme isn't being displayed as block. I'm using the carousel template for my index.html page and wanted to use the same theme on the rest of my pages, just without the carousel. However when I take out the carousel my second div sits under my nav bar.
Here is the code for my navbar:
<div class="navbar-wrapper">
<div class="container">
<nav class="navbar navbar-inverse navbar-static-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="index.html">Ecstatic Entertainment SK</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="active">What We Offer</li>
<li>Build Your Event</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>
</div>
</div>
</nav>
</div>
</div>
and a link to my fiddle, with my CSS on top of the bootstrap css:
https://jsfiddle.net/czz2Lm1n/
Your nav bar div (.navbar-wrapper) is in fact a block element, but it is also absolutely positioned.
Hence, it's been taken out of the normal flow and other divs ignore it. So your content ("second div") has moved up to the body edge since it doesn't see any other box to stop it.
In your code, one quick solution is to change the value of the position property for the class:
Original
.navbar-wrapper{position:absolute;top:0;right:0;left:0;z-index:20}
Revised
.navbar-wrapper{position:relative;top:0;right:0;left:0;z-index:20}
This works. Here's your fiddle, revised: https://jsfiddle.net/czz2Lm1n/3/
Now you can use position:absolute on all child elements of .navbar-wrapper, and they will position in relation to the containing block .navbar-wrapper.
If you want to learn more about the position property here's a good article:
https://developer.mozilla.org/en-US/docs/Web/CSS/position
Hope this helps. Good luck!
remove navbar-wrapper and container.
<nav class="navbar navbar-inverse navbar-static-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="index.html">Ecstatic Entertainment SK</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="active">What We Offer</li>
<li>Build Your Event</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>
</div>
</div>
</nav>
here is fiddle: https://jsfiddle.net/czz2Lm1n/2/
Related
<nav class="navbar navbar-inverse navbar-static-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="#">Grumblr</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">
<a href="#" class="dropdown-toggle"
data-toggle="dropdown" role="button"
aria-haspopup="true" aria-expanded="false">Dropdown
<span class="caret"></span></a>
<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 nav-pills pull-right">
<li role="presentation" class="active">test1</li>
<li role="presentation">test2</li>
<li role="presentation">test3</li>
</ul>
</div>
</div>
</nav>
the three buttons test1,test2,test3 are supposed to be on the right of navbars and vertical align middle. But it look likes:
img here
It there any css class can make it automatically aligned? Actually I'm new to css, just want to quickly build up my UI using bootstrap.....
#Ziqi, here's a link to a codeply project that implements your navigation bar. It just has a CSS class to add a margin between the buttons and the top of the navigation bar.
use height and padding to your anchor tag
.nav-pills a{
padding-top: 17px !important;
padding-bottom: 17px !important;
height: 54px !important;
}
or you can give class to anchor tag and use this css. you can inspect to the other anchor tag you can see the same css
I have a problem with Bootstrap's navbar: https://jsfiddle.net/2wwgt3to/1/
I'm making single page application and it turns out that bootstraps dropdown navigation menu for mobile is not really working well with it i.e. its not collapsing after clicking, I managed to solve this with adding data-toggle="collapse" data-target="#navbar" attributes but then the whole menu is collapsing even when it is not in dropdown form.
Remove data-toggle="collapse" data-target="#navbar" from
<div data-toggle="collapse" data-target="#navbar" id="navbar" class="navbar-collapse collapse">
Edited 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="#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="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>Default</li>
<li>Static top</li>
<li class="active">Fixed top <span class="sr-only">(current)</span></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
I have a bottom-fixed menu and want the toggle to dropup instead of down. I've tried all the solutions found in stackoverflow (like this one How to get a Bootstrap dropdown submenu to 'dropup'), wrapping up with .dropup class, or adding it to the element and so on, but nothing worked. This is my code:
EDIT TO ADD URL:
http://linares.kmturismo.com/
EDIT 2 - TO POINT OUT THE ERRORS:
One was the pointed out in the other answer. In addition, I gave it height: 50px; via custom css class, which stopped the menu to dropup.
<nav class="navbar navbar-default navbar-fixed-bottom">
<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="#">Linares de Mora</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>Que Hacer</li>
<li>Alojamiento</li>
<li>Historia</li>
<li>Comida</li>
<li class="dropdown">
Más <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>
</div><!--/.nav-collapse -->
</div>
</nav>
Check this link https://jsfiddle.net/edz80vw5/
<nav class="navbar navbar-default navbar-fixed-bottom">
<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="#">Linares de Mora</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>Que Hacer</li>
<li>Alojamiento</li>
<li>Historia</li>
<li>Comida</li>
<li class="dropup">
Más <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>
</div><!--/.nav-collapse -->
</div>
</nav>
The difference is made by the last li element of the first ul with class dropup instead of dropdown.
I am making a site with bootstrap. It is responsive, but not in the way I want it to be. When I change the screen size, the navbar tabs get cluttered together.
Here's my code:
http://pastebin.com/Rr2cG9KJ
Thanks so much!
Here is an example http://codepen.io/anon/pen/MeWzZN of correctly structured HTML using bootstrap. I believe this is what you are looking for. Please make it your own.
<nav class="navbar navbar-default navbar-static-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="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>Default</li>
<li class="active">Static top <span class="sr-only">(current)</span></li>
<li>Fixed top</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
Using the code from this SO Answer, I am trying to combine example 6 and 8 where I have a LOGO (Example 6) AND a Title/Brand (Example 8), which are always visible even in mobile screen (similar to example 8).
I have made minor changes, but I am not sure how to combine them.
Modified Bootply containing only example 6 and 8: Bootply
<nav class="navbar navbar-inverse navbar-static-top example6">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar6">
<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 text-hide" href="">Brand Text
</a>
</div>
<div id="navbar6" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
<li>Welcome {Name}</li>
<li class="active">Logout</li>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
<nav class="navbar navbar-inverse navbar-static-top example-8">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar8">
<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 text-hide" href="">Brand Text
</a>
</div>
<div id="navbar8" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
<li>Welcome {Name}</li>
<li class="active">Logout</li>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container-fluid -->
</nav>
I think I understand what you're asking. You could use the class navbar-text and include it in navbar-header. Here's a Fiddle. It still displays the text in mobile.
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<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="#"><span class="glyphicon glyphicon-equalizer" aria-hidden="true"></span></a>
<p class="navbar-text">brand text here yadda yadda</p>
</div>
EDIT: Then you need to configure the CSS like this:
.navbar-text {
position: absolute;
width: 100%;
left: 0;
text-align: center;
margin: auto;
padding-top: 10px;
}
Here's an updated Fiddle. You can adjust the height of the .navbar-text using padding or line-height.