Center li elements with ul - html

I have li elements in a nav menu, and I want to center the elements in the ul. I know this question has been asked many times, but I have tried almost everything and still cannot get it to work the way I would like. Here's the relevant portion of the code:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav"id="nav">
<li class="active">Home</li>
<li>Login</li>
<li>Registration</li>
</ul>
</div>
</div>
</nav>
Here's the HTML for the whole homepage

add this css code
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}

Related

My Bootstrap Navbar list is not coming to the center

I'm trying to center my menu list items in the bootstrap navbar. I've tried with the many CSS styles but it is still in the left.Below is my html and css please correct me if I'm wrong with the css.[To be more specific what I want is I want those menu items right below the Logo.][1]
<div class="header-botom">
<div class="content white">
<nav class="navbar navbar-default nav-menu" role="navigation">
<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="clearfix"></div>
<!--/.navbar-header-->
<div class="collapse navbar-collapse collapse-pdng" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav nav-font">
<li>Home</li>
<li>Ear Rings</li>
<li>Jewelry </li>
<li>Accessories</li>
</ul>
<div class="clearfix"></div>
</div>
<!--/.navbar-collapse-->
<div class="clearfix"></div>
</nav>
<div class="clearfix"></div>
</div
>
</div>
.nav-menu{
background: transparent;
border-radius: 0;
border: 0;
margin-top: 6px;
}
.navbar .{
text-align:center;
}
.navbar-nav li{
float: none;
display: inline-block;
}
[1]: https://i.stack.imgur.com/wxHSz.png
What you looking for is to add these css properties.
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
Possible Duplicate of this question.
JS Bin here
Add the following class in your custom css:
.navbar-nav {
text-align: center;
}
Demo:
.nav-menu {
background: transparent;
border-radius: 0;
border: 0;
margin-top: 6px;
}
.navbar . {
text-align: center;
}
.navbar-nav li {
float: none;
display: inline-block;
}
.navbar-nav {
text-align: center;
background: #e4e4e4;
}
<div class="header-botom">
<div class="content white">
<nav class="navbar navbar-default nav-menu" role="navigation">
<div class="collapse navbar-collapse collapse-pdng" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav nav-font">
<li>Home</li>
<li>Ear Rings</li>
<li>Jewelry </li>
<li>Accessories</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</nav>
<div class="clearfix"></div>
</div>
</div>
yes its seems like i got the solution for your problem, if you are using bootstrap
add the class into your custom css file
.collapse-pdng { padding: 0px 0px; margin: 0 auto; width: 32%; }
add the following class in your html file
<div class="text-center">
<div class="collapse navbar-collapse collapse-pdng" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav nav-font">
<li>Home</li>
<li>Ear Rings</li>
<li>Jewelry </li>
<li>Accessories</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
add the class text-center in div and put your whole menu in that class, i hope this will help you, please let me know

Bootstrap navbar: Width of left element affects position of element in the center

I'm new to bootstrap 3. At the moment I want to allign my navbar to the center. I did this with this approach, which works fine.
Now my Problem is that the width of my navbar-brand element affects the position of the centered stuff,e.g. the elements are moving to the left, if the branding gets bigger. Is there a way to position a element of the navbar at the "real" center of the screen?
It looks like that at the moment:
But I want at the real center of the screen like that, but with the brand:
My html:
<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 navbar-left" href="#"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
Services<span class="caret"></span>
<ul class="dropdown-menu">
<li>Stuff</li>
</ul>
</li>
<li>Karriere</li>
<li>Über uns</li>
<li>Kontakt</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
My CSS:
#media (min-width: $grid-float-breakpoint) {
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
}
Thanks for your help!
Making the root element of the navbarbrand have an absolute position seems to give the desired effect. This causes your nav links to be centered without regard to the navbarbrand element. NOTE: If your 'brand' text length gets too long, it will overlap the nav links. https://jsbin.com/juyanijeku/edit?output
.navbar-header {
position: absolute;
}
I've tried something like this
a.navbar-brand {
display: block;
float: none;
text-align: center !important;
}
.nav> li {
display:inline-block !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header text-center">
<a class="navbar-brand" href="#">
Brand
</a>
</div>
<div id="navbar">
<ul class="nav navbar-nav text-center">
<li>Karriere</li>
<li>Über uns</li>
<li>Kontakt</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>

Bootstrap menu button on smaller screen

i am trying to build my navigation bar using bootstrap, but i have the issues that when i have a small screen or window the mobile menu button doesn't appear in the right corner. What did i do wrong?
<nav class="navbar navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li>Home</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
and my css:
.navbar{
background-color:#fff;
border-bottom:1px solid black;
}
.navbar-nav > li > a{
color:#1E88E5 !important;
font-size:16px !important;
font-weight:bold !important;
display: block !important;
background-color:#fff !important;
}
.navbar-nav > li > a:hover{
color:#673ab7 !important;
background-color:#f0f5f5 !important;
}
You forgot navbar style class in your nav element (navbar-default or navbar-inverse). Styling toggle button depends on this class.
<nav class="navbar navbar-default navbar-fixed-top">
including bootstrap.min.css & bootstrap.css in links would do it.

How to center Bootstrap navigation items

I can't seem to figure out how to center the navigation items. I can place them either to the left or right but not center. Is there a simple work around?
<!-- Navigation -->
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<!-- Mobile navigation button -->
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Navigation items -->
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav">
<li>OUR PRODUCTS</li>
<li class="active">ABOUT</li>
<li>OUR TEAM</li>
<li>CONTACT</li>
</ul>
</div>
</div>
</div>
I've tried a few things but they're a little sloppy and caused some issues with mobile version. I'm looking for something a little more proper.
1) Use <ul class="nav nav-justified"... for the menu container.
2) Look at this codepen source:
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li
{
float: none;
display: inline-block;
}
3) Read the answer right there
There are three different ways to do something like You want, choose one.
You could easily find your answer, please try to do this alone next time, bro.
I believe you forgot to add or edit.
On your Bootstrap.css go find this class and edit on text-align:center. This will make your text navbar be centerized.
.navbar.navbar-collapse{
text-align: center;
}
If you still don't get it. You can take a look my example that i do on Bootply.
HTML
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<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 navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li>OUR PRODUCTS</li>
<li class="active">ABOUT</li>
<li>OUR TEAM</li>
<li>CONTACT</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</div>
CSS
#media (min-width: 620px) {
.navbar .navbar-nav {
display: inline-block;
float: none;
}
.navbar .navbar-collapse {
text-align: center;
}
}
DEMO
You could also use some custom CSS via flexbox.
.nav {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
justify-content: center;
float: none; // overwrites Bootstrap's float value
}
Try this one
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li
{
float: none;
display: inline-block;
}
.navbar-nav > li a{
text-decoration:none;
padding-left:15px;
}

Navbar links surrounding centered brand

I have an idea and not sure how to get it to work.
I have a bootstrap navbar on my site that has links and a "brand". The brand is centered within the navbar using this modification. Bootply
Instead of setting the navbar up like this:
{ (link)(link)(link)(....bunch of empty space....)(BRAND)(....bunch of empty space....)(link)(link)(link) }
I would like the navbar to set up like the diagram bellow.
{ (....bunch of empty space....) (link)(link)(link)(BRAND)(link)(link)(link) (....bunch of empty space....) }
I am very new to coding so please give me some time on the response to any questions you may have.
Thanks!
Just add padding to the left of the first link.
<nav class="navbar navbar-default" role="navigation">
<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="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">Center 1</li>
<li>BRAND</li>
<li>Center 3</li>
</ul>
</div>
</nav>
CSS
#media (min-width: 768px) {
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
.navbar-nav > li.navbar-right {
float: right !important;
}
}
Fiddle
http://jsfiddle.net/52VtD/9483/