Centering the Navigation Bar and its Elements in HTML - html

I am having problems creating a centred navigation bar where the child elements are also centred. I used nav-justified which almost works but then that seems to break the model so that when the window is smaller the collapsed menu stops working properly.
Html code is:
<header id="header">
<div class="container">
<!-- MOBILE MENU -->
<button id="mobileMenu" class="fa fa-bars" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse"></button>
<!-- NAV MENU -->
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul id="onepageNav" class="nav nav-justified"><!-- id="onepageNav" for homepage only -->
<li class="active">How</li>
<li>Help</li>
<li>Support</li>
<li>Consultancy</li>
<li>Blog</li>
</ul>
</nav>
<!-- /NAV MENU -->
</div>
</header>
Not sure what css to include so will add whatever you need to see.
There are a few questions on this already out there but the answers don't seem to work for me.
Really very grateful for any help and explanations as I am quite new to this.
Thank you

If you want them to have space between them, you're dealing with a common problem. Here's a good resource: http://css-tricks.com/equidistant-objects-with-css/
However, if you just want them simply arranged centered
nav { text-align: center; }
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
display: inline-block;
background: pink;
padding: 1em;
}
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul id="onepageNav" class="nav nav-justified"><!-- id="onepageNav" for homepage only -->
<li class="active">How</li>
<li>Help</li>
<li>Support</li>
<li>Consultancy</li>
<li>Blog</li>
</ul>
</nav>

Related

bootstrap dropdown use flexbox and space-between for content to fill space

I'd like to have two side menus in a dropdown in the navbar. In order to accomplish that I'd like to use flexbox. However the words are wrapping and i would like them not to and instead grow to fit the width of the content.
Tip: You'll need to expand the fiddle's rendering width to avoid the bootstrap collapse.
fiddle
<nav class="navbar navbar-default">
<div class="container-fluid">
<div>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<div class="flex-container">
<div>
<li>Left Side</li>
<li>Longer content on the left side</li>
</div>
<div>
<li>Log In</li>
<li>Sign Up</li>
</div>
</div>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
.flex-container {
display: flex;
justify-content: space-between;
}
I found the answer here. I was looking to avoid setting a fixed min-width
.dropdown-menu > li > a {
white-space: nowrap;
}
You need to override the bootstrap's default style on .dropdown-menu with something like,
.dropdown-menu {
min-width: 300px;
}
Hope this helps.
FYI.. you can accomplish this by applying the "text-nowrap" class available in Bootstrap 5 to the ul or div elements.
<ul class="dropdown-menu">
<div class="flex-container text-nowrap">
<div>

Bootstrap Fixed Navbar Behavior

Can somebody explain what is going on here?
I'm using bootstrap 3.3.7.
Why are .container elements invisible?
<!-- Navbar -->
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-header">
<a class="navbar-brand" href="#">Big Brother</a>
</div>
<div class="navbar-collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>Messages</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>something</li>
</ul>
</div>
</div>
<div class="container">
<h2>Invisible</h2>
</div>
Your <h2> is not invisible, it's hiding behind your navbar.
You're using a navbar that uses fixed positioning. This takes it out of the normal document flow where it doesn't take up space so the elements after it begin to flow as if it wasn't there.
If you add padding-top: 50px; to <body> you will see your <h2>.
If you read through the Bootstrap Navbar Docs you'll notice a callout that says Body padding required.

How to make Bootstrap header item and dropdown-menu the same width?

I have this header in my Bootstrap template:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
//Some unrelated stuff
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
//Some unrelated stuff
</ul>
<ul class="nav navbar-nav pull-right-custom">
<li class="dropdown">
DDButtonText <strong class="caret"></strong>
<ul class="dropdown-menu">
Test
</ul>
</li>
</ul>
</div>
</div>
</nav>
What I'm trying to accomplish is to make the dropdown menu the same width as the 'DDButtonText' thing. I tried setting min-width to dropdown-menu but it was different for each browser. It was alright in my Firefox but Chrome and other browsers showed a little different sizes.
How do I make my menu be the same size as the button regardless of browser, always?
You can try adding this:
CSS:
.nav .dropdown-menu{
width: 100%;
min-width: inherit;
}
Bootply: http://www.bootply.com/MfkTjxasD7

Twitter-Bootstrap navigation header with three elements (iOS style)

Im trying to do an horizontal bar that mimics the Navigation view on iOS, thats saying:
Back Logo SomeButton
Left Center Right
After fiddling with many solutions I've been able to get something similar, using
<nav class="navbar navbar-default" role="navigation">
<a class="navbar-brand" href="#"><img src="static/img_nav/logo_white_trans.gif"> </a>
<div class="navbar-header navbar-collapse">
<ul class="nav navbar-nav pull-left">
<li> < Back</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li>Button</li>
</ul>
</div>
</nav>
with this CSS:
.navbar-brand
{
position: absolute;
width: 100%;
left: 0;
text-align: center;
margin: auto;
}
.navbar-brand img {
height: 20px;
}
When I do the browsing in my phone everything works as I expected, but when I go to larger screens, left and right buttons get together.
Left Right Center
Does anyone know why?
Try this:
The reason for your issue is :
In navbar-collapse the width is auto, So
Set width:100% in your navbar-header tag
<div style="width:100%" class="navbar-header navbar-collapse">
DEMO

Bootstrap mobile menu opening behind first section content

Okay I am having an issue with my bootstrap 3 mobile menu, it is opening under my first section content. After you scroll down it works fine, it just has that issue on the first section.
You can see the issue here. Just reduce the screen size till you see the mobile menu button.
Also here is my html for my nav:
<div class="navbar">
<div class="container">
<div class="navbar-header">
<!-- Brand -->
<img class="logo" width="45" height="45" alt="lightning bolt logo" src="img/logo.png"></img>
<!-- Mobile Navigation -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="ion-navicon toggle-icon"></span>
</button>
</div>
<!-- Main Navigation -->
<nav class="collapse navbar-collapse navHeaderCollapse" id="myScrollSpy" role="navigation">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>Portfolio</li>
<li>About</li>
<li>Team</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
I have double checked my files and nothing is causing this, anyone ran into this issue before?
Adding z-index: 9999; style to .navbar class should work. The content from first section is overlapping with the navbar. Adding a high enough z-index makes sure that it'd be above every other element on the page.
.navbar {
z-index: 9999;
}