Center <a> element in navbar header parent - html

Hello stackoverflow people, I need help with centering my Website Title, here is the print screen of website:
As you can see Website title is in the left of the navbar here is my html:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<!--Mobilus buttonas-->
<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="#">Website title</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul id="top-menu" class="nav navbar-nav navbar-left main_nav">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
<li>Works</li>
</ul>
<ul id="top-menu" class="nav navbar-nav navbar-right main_nav">
<li>Team</li>
<li>Pricing</li>
<li>Blog</li>
<li>Contacts</li>
</ul>
</div>
</div>
</nav>
I'am using bootstrap so there is no point posting css, so I will give you jsfiddle so it could be simplier: https://jsfiddle.net/fNPvf/18964/ . So i repeat, I don't know how to make Website Title in the center of website?

Try this:
.navbar-brand {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
}

Build something like col5-col2-col5. You maybe have to adjust this for other resolutions. Centering stuff without flexbox is always a pain.
Like this:
<header id="header">
<!--Meniu laukas-->
<div class="menu_area">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="row">
<div class="col-md-5">
<ul id="top-menu" class="nav navbar-nav navbar-left main_nav">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
<li>Works</li>
</ul>
</div>
<div class="col-md-2">
<div class="navbar-header">
<a class="navbar-brand" href="#">Website title</a>
</div>
</div>
<div class="col-md-5">
<ul id="top-menu" class="nav navbar-nav navbar-left main_nav pull-right">
<li class="active">Home</li>
<li>About</li>
<li>Services</li>
<li>Works</li>
</ul>
</div>
</div>
</div>
</nav>
</div>
</header>
https://jsfiddle.net/fNPvf/18972/

add the following class in your css
you may adjust this value for various media queries and add the class to the container check the following fiddle https://jsfiddle.net/fNPvf/18975/
.center-container{width:705px;}

Related

I want my navigation bar in horizontal but it is vertical

Please help through this problem to bring in horizontal navigation
The code is:-
<div class="navbar navbar-inverse navbar-fixed-top " id="menu">
<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="navbar-collapse collapse move-me">
<ul class="nav navbar-nav navbar-left">
<li>Hello <?php echo $_SESSION['loggedin_name']; ?></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>ATTENDANCE </li>
<li>PROFILE </li>
<li>TIMETABLE</li>
<li> STATISTICS</li>
<li>LOGOUT</li>
</ul>
</div>
</div>
Are you are using the latest Bootstrap?
I think you have to add navbar-default to your <div class="navbar"> and navbar-nav to your <ul class="nav">
<div class="container">
<h1>Bootstrap Site</h1>
<div class="navbar navbar-default">
<div class="navbar-inner">
<div class="container">
<ul class="nav navbar-nav navbar-right">
<li>ATTENDANCE </li>
<li>PROFILE </li>
<li>TIMETABLE</li>
<li> STATISTICS</li>
<li>LOGOUT</li>
</ul>
</div>
</div>
use this bootstrap cdn link it will work.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

How to prevent menu from stacking on top of each other in Bootstrap?

When I shrink the window, I want the menu to stay on the same line as the logo in medium screen. Right now it's stacking like this Link to image. How do I fix it?
<nav class="navbar navbar-default">
<div class="navbar-header">
<a class="navbar-brand" href="#">LOGO</a>
</div>
<ul class="nav navbar-nav hidden-xs">
<li>Guides</li>
<li>Courses</li>
<li>Tutorials</li>
<li>Top Authors</li>
</ul>
<ul class="nav navbar-nav navbar-right" >
<li>Login</li>
<li>Sign Up</li>
</ul>
<!--collapse navbar -->
Hard to say because there is no CSS posted, but you can generally use inline-block to position the elements on the same line. Roughly:
.navbar-header {
display:inline-block;
vertical-align:middle;
width:30%;
text-align:left;
}
.nav {
display:inline-block;
vertical-align:middle;
width:65%;
text-align:right;
}
It maybe due to some discrepancy in adhering to bootstrap standard navbar. Below is a snippet implementing your code, but I applied it to the template provided in the Bootstrap navbar documentation, please let me know if you face any issues.
<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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav hidden-xs">
<li>Guides</li>
<li>Courses</li>
<li>Tutorials</li>
<li>Top Authors</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Login</li>
<li>Sign Up</li>
</ul>
</div>
</div>
</nav>
JSFiddle Demo

Two lists in navbar using 'navbar-right', displays second list first?

In Bootstrap 3 I'm trying to create a navbar which will have to ul, both of which will align to the right. But when I add navbar-right to both ul's, they both align to the right, but the second ul in the markup displays first? What do I need to do to get them to display in the proper sequence?
<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="#">Brand</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Register</li>
<li>Login</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
Link to Codeply: https://www.codeply.com/go/LibLIdo8NW
Just write the ul for Register and Login first that will solve your issue.
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>Register</li>
<li>Login</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
Updated link to your demo
Update:
The class navbar-right has the property float: right!important; which pushes the first element to the right most of the screen.
Overriding this property would be another hack :)
This is the right process.
Check this link.
In order to have your desired result you just have to switch the ul's for these elements.
Take navbar-right class to container for both UL's.
<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="#">Brand</a>
</div>
<div class="collapse navbar-collapse navbar-right">
<ul class="nav navbar-nav ">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav ">
<li>Register</li>
<li>Login</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container">
<div class="text-center">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</div>

bootstrap 3: side navbar on collapse into top navbar

I don't think i've worded this properly so let me elaborate i'm trying to have my side navbar collapse into a button that functions as a top button navbar so this [actually nav-pills];
but collapses into this into the header tag:
on the top with this dropbox function.
currently my code has the dropdown occur where the sidebar would be
here's the code i'm using, Ive made no custom CSS adjustments other than color changes.
<header class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<h1 class="brand">bootstrap</h1>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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>
</nav>
</header>
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3"><!--aside-->
<aside>
<div class="collapse navbar-collapse" id="collapse">
<h4>Menu</h4>
<ul class="nav nav-pills nav-stacked">
<li>home</li>
<li>about</li>
<li>gallery</li>
<li>CV</li>
<li>link</li>
<li>Contact</li>
</ul>
</div>
</aside>
</div>
hope this makes sense thanks!
found the visible and hidden classes this worked
<header class="container"><!--header-->
<div class="row">
<div class="col-lg-12">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<h1 class="brand">John Doe</h1>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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>
</nav>
</div>
</div>
<div class="collapse navbar-collapse" id="collapse">
<ul class="nav navbar-nav visible-xs">
<li>project 01</li>
<li>project 02</li>
<li>project 03</li>
<li>About</li>
<li>link</li>
<li>Contact</li>
</ul>
</div>
</header><!--header-->
<div class="container"><!--content area-->
<div class="row">
<aside class="col-lg-3 col-md-3 col-sm-3"><!--aside-->
<div class="collapse navbar-collapse" id="collapse">
<ul class="nav nav-pills nav-stacked hidden-xs">
<h4>Works</h4>
<li>project 01</li>
<li>project 02</li>
<li>project 03</li>
<li>About</li>
<li>link</li>
<li>Contact</li>
</ul>
</div>
</aside><!--aside-->

bootstrap: Can't create a navbar?

I am using twitter bootstrap v3 to create a navbar and I follow their documentation
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="/">Title</a>
<ul class="nav">
<li>About</li>
<li>Feedback</li>
<li>whoami</li>
</ul>
</div>
</div>
</div>
But the navbar is not created. Here is the demo
What is that I am missing here?
Actually, you need the class "navbar-nav" on your ul :
<h1>Hello Plunker!</h1>
<div class="navbar">
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
Note that you can change h1 for a link directly in the nav like this:
<div class="navbar">
<a class="navbar-brand" href="#">Hello Plunker!</a>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
The reason that documentation page doesnt work for you is because it's using a different style sheet.
If you use that documentation page's stylesheet..it'll work.
<link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" />
Documentation is just old.
I was looking at wrong version of docs(v.2.3.2), the correct documentation for v3.0.0 is here and that fixed my issue
<nav class="navbar navbar-default navbar-fixed-top" 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-ex5-collapse">
<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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex5-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
The demo is updated and can be found here