Center Bootstrap li elements on center of responsive page - html

I am trying to get all of the elements in the navbar to always display in the center of the navbar and thus the center of the page, but still they are pulling to the left. When I remove my bootstrap libary, they are centered, so there is a conflict somewhere but I am not sure what and I want to use bootstrap.
My custom CSS is also linked AFTER the bootstrap one.
Any great is greatly appreciated.
HTML:
<div class="navbar navbar-default">
<div class="container-fluid">
<div class="container">
<ul class="nav navbar-nav">
<li>Home</li>
<li>About</li>
</ul>
</div>
</div>
</div>
CSS:
.navbar {
margin-bottom: 0px;
border-radius: 0px;
}
.nav {
list-style:none;
margin:0;
padding:0;
text-align:center;
}
.nav li {
display:inline;
}
.nav a {
display:inline-block;
padding:10px;
}
.navbar-default {
background: #900000;
border: none;
}

By default, Bootstrap's css floats .navbar-nav to the left. Hence:
#media (min-width: 768px)
.navbar-nav {
float: left;
margin: 0;
}
You need to overwrite this property. I suggest giving a unique class maybe like .myNav and resetting this float. Also adding a display:inline-block
<div class="navbar navbar-default">
<div class="container-fluid">
<div class="container">
<ul class="nav navbar-nav myNav">
<li>Home</li>
<li>About</li>
</ul>
</div>
</div>
</div>
CSS:
.myNav{
float:none;
display:inline-block;
}
Finally, add a text-align:center to the wrapping navbar element to center the content inside
.navbar {
margin-bottom: 0px;
border-radius: 0px;
text-align:center;
}

Here is a possible solution:
HTML:
<div class="navbar navbar-default">
<div class="container-fluid">
<div class="container">
<ul class="nav navbar-nav navbar-center">
<li>Home</li>
<li>About</li>
</ul>
</div>
</div>
</div>
CSS:
.navbar {
margin-bottom: 0px;
border-radius: 0px;
}
.navbar-center {
width: 100%;
margin: 0 auto;
text-align: center;
text-align:center;
}
.nav li {
display:inline-block;
float: none;
}
.nav a {
padding:10px;
}
.navbar-default {
background: #900000;
border: none;
}
Fiddle: https://jsfiddle.net/j2ska9ym/

Related

vertical align links and logo in nav bar

I'm having trouble vertically aligning the links and the logo inside the list any idea what i can to fix it?
Here is the code in codepen.
http://codepen.io/tacoxlegendary/pen/VjXqkA?editors=1100
<body>
<nav>
<div class="wrapper ">
<ul class="cf">
<li id="logo">LOGO</li>
<li>SIGN IN</li>
<li>LOCTION</li>
<li>TEAM</li>
<li>ABOUT</li>
</ul>
</div> <!-- wrapper end -->
</nav>
.wrapper {
max-width: 1120px;
margin: 0 auto;
}
nav {
background-color: #F7FDFE;
}
nav ul li {
display: inline-block;
color: #45494D;
float: right;
padding: 10px;
font-size: 14px;
}
nav ul #logo {
float: left;
font-size: 30px;
}
Add padding:0 to nav ul #logo
.wrapper {
max-width: 1120px;
margin: 0 auto;
}
nav {
background-color: #F7FDFE;
}
nav ul li {
display: inline-block;
color: #45494D;
float: right;
padding: 10px;
font-size: 14px;
}
nav ul #logo {
float: left;
font-size: 30px;
padding:0;
}
<nav>
<div class="wrapper ">
<ul class="cf">
<li id="logo">LOGO</li>
<li>SIGN IN</li>
<li>LOCTION</li>
<li>TEAM</li>
<li>ABOUT</li>
</ul>
</div> <!-- wrapper end -->
</nav>
a simple way to center the navbar and logo in the center of navbar is to set a height to navbar and give the same value as line-height to li
like
nav {
height: 70px;
}
ul.cf {
line-height: 70px;
}

How can I display an inline list with a fixed position?

I'm trying to display an inline list, with the first 5 elements pulled left, and the last 2 elements pulled right, as shown below:
This inline list needs to cling to the top of the screen when the user scrolls past it, and so I need to set position: fixed and top: 0px. However, when I try to do this, the left side of the list ends up stacking onto the right side, as shown below:
Is there any way to preserve the inline display of the list while using a fixed position? If not, what are other solutions to this issue?
Here's my code, sorry if it's a mess or not formatted correctly. I've just started playing around with web dev:
CSS:
.menu-header {
background-color: #2658C9;
}
.menu-header .pull-left {
margin-left: 10%;
overflow: hidden;
white-space: nowrap;
}
.menu-header .pull-right {
margin-right: 10%;
overflow: hidden;
white-space: nowrap;
}
.menu-header ul {
padding-left: 0px;
display: inline;
}
HTML:
<div class="menu-header">
<div class="row">
<ul class="menu-header-list">
<div class="pull-left">
<li>Home</li>
<li>Tech</li>
<li>Tutorials</li>
<li>Articles</li>
<li>Papers</li>
</div>
<div class="pull-right">
<li>About</li>
<li>Contact</li>
</div>
</ul>
</div>
</div>
Any help would be much appreciated, as I've been trying to fix this for hours. Changing the display & using floats hasn't fixed the problem. Thanks!
Try this Fiddle
.navbar {
background: #2658C9;
color: white;
position: fixed;
top: 0;
width: 100%;
}
.navbar-default .navbar-nav > li > a{
color: white;
}
<nav class="navbar navbar-default">
<div class="container-fluid">
<ul class="nav navbar-nav pull-left">
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li>Link</li>
<li>Link</li>
</ul>
</div>
</nav>
The problem is caused because you didn't set width:100% to your header.
.menu-header{
width:100%;
}
Look into these CSS:
.menu-header {
background-color: #2658C9;
width:100%;
overflow:hidden;
}
.menu-header .pull-left {
float:left;
}
.menu-header .pull-right {
float:right;
}
.menu-header ul {
padding-left: 0px;
}
.menu-header ul li {
display:inline-block;
}
float pull left and right and display li in inline-block
this is the solution for you
.row{
width:100%;
position:fixed;
}
fix your .row not the 'ul'
for the complete code , I have created a complete code.if you want you cant try it.
<!DOCTYPE html>
<html>
<head>
<title>working with bootstrap offline</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="index.css">
<style type="text/css">
div.menuone ul li{
list-style-type: none;
display: inline;
margin:20px;
}
div.menutwo ul li{
ist-style-type: none;
display: inline;
margin: 30px;
}
div.menuone ul li a, div.menutwo ul li a{
color: white;
}
div.menuone{
padding-top: 30px;
}
div.menutwo{
padding-left: 50px;
padding-top: 30px;
}
</style>
</head>
<body>
<div class="menu-header">
<div class="row" style="background-color:blue;">
<div class="col-md-8 menuone">
<ul>
<li>Home</li>
<li>Tech</li>
<li>Tutorials</li>
<li>Articles</li>
<li>Papers</li>
</ul>
</div>
<div class="col-md-4 menutwo">
<ul>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</ul>
</div>
</div>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</body>
</html>

Put navbar next to logo in white box with bootstrap

I have my logo on the left with a white background in the header but my navbar keeps going underneath this on the right. I don't understand why this is happening. Also I don't think my navbar list is going straight across.
body {
background-color: #832040;
}
.navbar-default {
width: 100%;
height: 100px;
margin: 15px 0 0;
padding: 0;
background-color: #FFF;
}
.navbar ul.nav li a {
font-family: 'Righteous', sans-serif;
font-size: 38px;
color: #000;
padding: 25px;
margin: 0;
}
.navbar ul.nav li a:hover {
background: #000;
color: #fff;
height: 40px;
}
.logo {
width: 320px;
padding: 15px;
}
<div class="navbar-default">
<div class="logo">
<img src="HairSite/KatiesKuts-Logo.png">
</div>
<div class="navbar">
<div class="navbar nav pull-right">
<ul class="nav navabar-nav">
<li>Home</li>
<li>Bio</li>
<li>Appointments</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
you have missed out some proper html structure and classes bootstrap requires.
<div class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<div class="logo">
<img src="HairSite/KatiesKuts-Logo.png">
</div>
</div>
<div class="navbar">
<ul class="nav nav navbar-nav navbar-right">
<li>Home</li>
<li>Bio</li>
<li>Appointments</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
you could refer the following links for further references;
Logo Nav by Start Bootstrap
Navbar example form Bootstrap
This might help or give you some ideas. You're missing some HTML and I don't believe navbar-default was a class in 2.3.2.
body,
html {
background-color: #832040;
}
.navbar .navbar-inner {
background: white;
border: none;
border-radius: 0;
}
.navbar .navbar-inner .nav > li > a {
font-family: 'Righteous', sans-serif;
font-size: 15px;
color: #000;
padding-top: 50px;
padding-bottom: 50px;
}
.navbar .navbar-inner .btn-navbar {
margin-top: 45px;
}
.navbar .navbar-inner .nav > li > a:hover {
background: #000;
color: #fff;
}
#media (max-width: 991px) {
.navbar .navbar-inner .nav > li > a {
padding-top: 10px;
padding-bottom: 10px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">
<img src="http://placehold.it/320x100/000">
</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li>Home
</li>
<li>Bio
</li>
<li>Appointments
</li>
<li>Contact
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
</div>

How can I set my menu in center of whole screen using bootstrap?

I wanted the menu in center using navbar. Is it possible to do it?
HTML:
<header class="header-area">
<nav class="header-nav navbar">
<div class="container-fluid">
<ul class="nav navbar-nav list-inline text-center">
<li>About us</li>
<li>Work</li>
<li><img src="images/logo1.png" class="img-responsive" alt="website-logo" /></li>
<li>Shop</li>
<li>Contact</li>
</ul>
</div>
</nav>
</header>
CSS:
.header-area {
background: url("images/background1.jpg") no-repeat 0 0 / 100% 100%;
color: #84828D;
}
.header-nav .nav.navbar-nav {
width: 80%;
margin: auto;
float: inherit;
}
Here's is a sample picture :
Increase width here
.header-nav .nav.navbar-nav {
width: 100%;
margin: auto;
float: inherit;
}
And add following CSS
.navbar .nav, .navbar .nav > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: middle;
}
.navbar-inner {
text-align:center;
}
Note: you have ** here inside class,
<nav class="header-nav navbar**">**
it should be be
<nav class="header-nav navbar">**
Fiddle Example

Add margin to inline-block element independently

I want to apply an amount of space before an element in an unordered list. Here is the URL:http://hottdoggfilms.com. I try to centralize the dog's picture with logo in between the other list elements. But there is uneven space between the elements "Recent Work" and "About Us". My markup is:
<div id="navbar" class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<h1><a class="brand" id="cf" href="#"><img class="bottom" src="hottdogg.png" data-min-width-481="hottdogg.png" alt="Tipit"><img class="top" src="hottdogg.png" data-min-width-481="hottdoggHover.png" alt="Tipit"></a></h1>
<nav class="nav-collapse collapse" role="navigation">
<h2 class="visuallyhidden">Navigation</h2>
<ul class="nav">
<li class="active">Home</li>
<li>Recent work</li>
<li class="divider"></li>
<li style="margin-left:20px">About us</li>
<li>Contact us</li>
</ul>
</nav>
</div>
</div>
</div>
And the CSS:
#navbar .nav {
font-size: 0;
text-align: center;
white-space: nowrap;
float: none;
margin: 0;
}
#navbar .nav li {
display: inline-block;
float: none;
}
#navbar .nav a {
margin-bottom: 0;
font-size: 16px;
line-height: 37px;
height: 37px;
padding-left: 1.4em;
padding-right: 1.4em;
}
#navbar .divider {
width: 186px;
}
To me, the nav is quite confusing, with the divider and all.
Why not to go for a simpler solution?
http://codepen.io/anon/pen/IeLCf
nav {
margin:0 auto;
border:1px dashed black;
text-align:center;
}
nav a {
position:relative;
top:-100px;
display:inline-block;
vertical-align:middle;
padding:10px;
text-align:left;
}
<nav>
Home
LOOOOOOONG
<img src="http://hottdoggfilms.com/hottdoggHover.png" alt="" />
shrt
LOOONG
</nav>
Try to add width to #about-us' element 100px and lower the width of the .divider element to 145px.
I agree with the above answer, having the image as part of your navigation is a better solution.
However, if you want to keep what you have now, you can use the :nth-child selector.
http://www.w3schools.com/cssref/sel_nth-child.asp
https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child
in your case:
.nav > li:nth-child(3) {
margin-left: 60px; //as much as you need
}
//and for when the menu collapses
.nav > li:nth-child(3).small-screen {
margin-left: 0; //or whatever the default is
}