I need to position my navbar within a div - html

I've tried everything from text-align to setting margins. I want the nav bar to be centered horizontally and at the bottom of the div vertically.
html: http://www.joekellywebdesign.com/businesssample/index.html
<div id="navbar">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a class="MenuBarItemSubmenu" href="projects.html">Projects</a>
<ul>
<li>Restaurant</li>
<li>House</li>
<li>Mall</li>
</ul>
</li>
<li>About</li>
<li><a class="MenuBarItemSubmenu" href="services.html">Services</a>
<ul>
<li><a class="MenuBarItemSubmenu" href="residential.html">Residential</a>
<ul>
<li>Housing</li>
<li>Storage</li>
</ul>
</li>
<li>Business</li>
<li>Government</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
css: http://www.joekellywebdesign.com/businesssample/css/styles.css
/* CSS Document */
* {
margin:0px;
padding:0px;
}
body {
background-color:#FF0;
}
#wrapper {
width:900px;
margin:10px auto;
background-color:#FFF;
}
#logo {
float:left;
width:200px;
background-color:#FFF;
}
#navbar {
float:right;
text-align:center;
width:700px;
margin: auto;
background-color:#FFF;
}

You could do something like this:
<style type="text/css">
div#container {
position:relative;
width: 500px;
height: 300px;
border: 1px solid black;
}
div#menu-container {
position: absolute;
bottom: 0;
width: 100%;
}
div#menu {
position: relative;
text-align: center;
}
</style>
<div id="container">
<div id="menu-container">
<div id="menu">
Hello World!
</div>
</div>
</div>
Check out this jsFiddle for a demonstration.

Using an absolute position would easily get it to the bottom:
You'd apply this to the #navbar: position: absolute; bottom: 0px;
Then you'd apply this to the parent: position: relative;
However, now that you've applied an absolute position, you should use a similar technique to center it horizontally. Since your navbar is 700px, we can use some math to center it using the same absolute position.
You'd apply this to the #navbar: left: 50%; margin-left: -350px;
Working example: http://jsfiddle.net/ky9av/

You can try this.
ul.MenuBarHorizontal {
margin-top: 8%;
float: right;
}

You can try with this,
ul.MenuBarHorizontal {
cursor: default;
font-size: 100%;
list-style-type: none;
margin: auto;
padding: 0;
width: 512px;
}
Secondly, as per your design, the navbar ends exactly where you ul ends,
so you might try this
#navbar {
background-color: #FFFFFF;
float: right;
margin: auto;
margin-top: 49px;
text-align: center;
width: 700px;
}

Related

Position Nav Bar Top Right

I am trying to move my Nav Bar to the Top Right with my logo on the Top Left all on one line. But I am unable to do so and I could use some help. I am new to learning HTML and CSS. The nav bar currently rests below the name/logo on the top right.
Demo
.container{
padding: 40px 40px 40px 40px;
margin: 10px 10px 10px 10px;
position: relative;
display: block;
text-shadow: 1px 1px 1px rgba(0,0,0,0.2);
text-align: left;
border: 1px solid blue;
color:white;
}
.container h1{
text-align: left;
font-size: 50px;
}
.container nav{
height: 70px;
line-height: 70px;
border: 1px solid green;
}
.container nav ul {
list-style: none;
width: 100%;
border: 1px solid red;
text-align:right
}
.container nav ul li {
display: inline-block;
font-size: 100%;
color:white;
margin-right: 0;
border : 1px solid yellow;
}
<div class="container">
<header>
<h1>Srikanth Gowda</h1>
</header>
<nav class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</div>
One way would be to use float.
Per documentation found on MDN Web Docs
The float CSS property specifies that an element should be placed along the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the web page, though still remaining a part of the flow (in contrast to absolute positioning).
Learn more about float
Add the following to your CSS
.container header {
float: left;
}
Change your .container nav to:
.container nav{
height: 70px;
line-height: 70px;
border: 1px solid green;
float: right;
}
This will get you what you want...
Working demo
A couple of quick and dirty methods as starting points:
Method 1, using flexbox:
.container{
display: flex;
align-items: center;
justify-content: space-between;
}
nav ul {
display: flex;
list-style: none;
}
nav ul li {
margin-right: 20px;
}
<div class="container">
<header>
<h1>Srikanth Gowda</h1>
</header>
<nav class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</div>
Method 2, using floats:
header {
float: left;
}
nav {
float: right;
}
nav ul {
list-style: none;
padding-top: 18px;
}
nav ul li {
display: inline-block;
margin-right: 5px;
}
<div class="container">
<header>
<h1>Srikanth Gowda</h1>
</header>
<nav class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</div>
you can use flex box property. and float right and left to align your div
.container{
position: relative;
display: block;
text-shadow: 1px 1px 1px rgba(0,0,0,0.2);
height:70px;
border: 1px solid blue;
color:blue;
}
.container h1{
font-size: 50px;
}
.container .navbar{
height: auto;
line-height: auto;
border: 1px solid green;
float:right;
}
.container .navbar ul {
list-style: none;
width: auto;
border: 1px solid red;
}
.container .navbar ul li {
display: inline;
font-size: 100%;
color:blue;
border : 1px solid yellow;
}
.header{
float:left;
}
.d1{
float:clear;
height:100px;
width:1000px;
}
<div class="container">
<div class="header">
<h4>Srikanth Gowda</h4>
</div>
<div class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</div>
</div>
<div>
<div class="d1">
rest of your content
eferfer
</div></div>
When you want to align elements in a div on the same line but on different sides always use the float property. You can change the header's position to left and nav to right by using the float property as below:
.header{
float:left;
}
.container nav{
height: 70px;
line-height: 70px;
border: 1px solid green;
float: right;
}
There are two ways. the first one is given below.
.container header{
display:inline-block;
float:left;
}
.navbar{
display:inline-block;
float:right;
}
The second method is you can put them in a table like below.
<div class="container">
<table>
<tr>
<td>
<header>
<h1>Srikanth Gowda</h1>
</header>
</td>
<td>
<nav class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</td>
</tr>
</table>
</div>

Center align Logo and align UL horizontally around it

I am trying to capture a layout that I have seen a few different places. The layout has a fixed header with an image centered, and then a horizontal UL that is split around the logo. Attached is the image that I feel represents this.
I need a suggestion to achieve splitting the UL around logo. Right now the UL is always under and not split.
http://jsfiddle.net/jgac8/1/
Here is some markup that I have been attempting:
HTML
<header>
<h1 id="logo"></h1>
<nav>
<ul>
<li>about</li>
<li>services</li>
<li>location</li>
<li>contact</li>
</ul>
</nav>
</header>
CSS
header {
width: 100%;
height: 150px;
text-align:center;
position: fixed;
top: 0;
left: 0;
background:#FF7D0D;
border-bottom: 1px solid #CCC;
z-index:100;
}
#logo {
display: inline-block;
padding:5px 0 0 0;
width: 80px;
height: 150px;
background: url(../img/PP_Logo_Vert_White.png) center no-repeat;
}
nav {
padding: 0px;
margin: 0px;
font-size:16px;
font-weight: 100;
clear:left;
}
nav ul {
padding: 0px;
margin: 0px;
list-style: none;
}
nav li {
display: inline-block;
padding: 0 50px;
}
You might have to do a bit of tweaking but I believe it is what you want.
HTML
<header>
<h1 id="logo"></h1>
<nav id="left">
<a href="#" ></a>
<ul>
<li>about</li>
<li>services</li>
</ul>
</nav>
<nav id="right">
<a href="#" ></a>
<ul>
<li>about</li>
<li>services</li>
</ul>
</nav>
</header>
CSS
header {
width: 100%;
height: 150px;
text-align:center;
position: fixed;
top: 0;
left: 0;
background:#FF7D0D;
border-bottom: 1px solid #CCC;
z-index:100;
}
#logo {
display: inline-block;
padding:5px 0 0 0;
width: 80px;
height: 150px;
background: url(http://findicons.com/files/icons/2141/web_design_creatives/128/small_smile.png) center no-repeat;
}
#left{position:absolute; left:10%; top:5px; list-style:none}
#right{position:absolute; right:10%; top:5px; list-style:none}
li{list-style:none}
There are many ways to go about this. Depending on how dynamic your site will be. If you are creating it with static html and css I would simply create a container, put three divs inside the container splitting it up how you want. In the first and third div create two separate menus. In the center put the logo. Something like the code below. At a certain width you can create some css media queries to bring it down and make it one navigation.
The very basic idea:
Example of html:
<div class="container">
<div class="left-nav">
</div>
<div class="logo">
</div>
<div class="right-nav">
</div>
</div>
Example CSS:
.container {
float: left;
width: 100%;
margin: 0;
padding: 0;
}
.left-nav {
float: left;
width: 400px;
}
.right-nav {
float: left;
width: 400px;
}
.logo {
float: left;
width: 200px;
}

CSS Changing position of div to absolute ruins the layout

I have a div(bottom) at the bottom of my page.
It has a background image and another div(bottomnav) with an unordered list for the navigation.
When I change bottomnav's position to absolute the entire bottom div gets shifted up into the div above it. also, i have another div called cc. that one i can change to absolute without any problems.
This is my code:
html
<div id="bottom">
<div id="bottomnav">
<ul>
<li>Home</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div>
<div id="cc">©2014 European Homemakers</div>
and this is my css:
#bottom
{
background-image:url(../Images/home_bottom.png);
width: 960px;
margin-left:auto;
margin-right:auto;
min-height: 100px;
background-repeat:no-repeat;
position:relative;
}
#bottomnav
{
font-size: 20px;
}
#bottomnav ul {
list-style-type: none;
height:auto;
}
#bottomnav li
{
display:inline;
padding:20px;
}
#bottomnav a {
text-decoration: none;
color: #FF9200;
}
#cc
{
text-align:right;
color: #FF9200;
position:absolute;
bottom: 5px;
right: 5px;
font-size:20px;
}
Im pretty new to web design so Im not sure why changing bottomnav to absolute changes the layout.
Working Fiddle
First of all you are not closing #bottom div, Secondly as #bottom is position: relative so any thing inside it will be absolute relative to this div. Therefore, remove footer div out of it.
HTML
<div id="bottom">
<div id="bottomnav">
<ul>
<li>Home
</li>
<li>Services
</li>
<li>Contact
</li>
</ul>
</div>
</div>
<div id="cc">©2014 European Homemakers</div>
CSS
#bottom {
background-image:url(../Images/home_bottom.png);
width: 960px;
margin-left:auto;
margin-right:auto;
min-height: 100px;
background-repeat:no-repeat;
position:relative;
}
#bottomnav {
font-size: 20px;
}
#bottomnav ul {
list-style-type: none;
height:auto;
}
#bottomnav li {
display:inline;
padding:20px;
}
#bottomnav a {
text-decoration: none;
color: #FF9200;
}
#cc {
color: #FF9200;
font-size:20px;
position: absolute;
bottom: 5px;
right: 5px;
}
If you are expecting for footer to always be at bottom regards the content, then this will help you.
DEMO
You need to change you structure.

UL/LI positioning spacing

I have been in this problem for a while now, everytime I resize the navigation bar it keeps on adding 1 line at the bottome if the size ddint match. can anyone help me delete that little space after the contact me tab? thanks in advance.
this is the link of the outcome
my codes is this
obj.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="obj1.css">
<title>Objective 1</title>
</head>
<body>
<div class="header">
<div class="nav">
<ul>
<li class="navbutton">About Us</li>
<li class="navbutton">Our Team</li>
<li class="navbutton">Education</li>
<li class="navbutton">Health Care</li>
<li class="navbutton">Advertising</li>
<li class="navbutton">Contact Us</li>
</ul>
</div>
</div>
</body>
</html>
obj1.css
body {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
ul {
display: inline-block;
list-style-type:none;
margin:0;
padding:0;
}
li {
float: left;
}
.header{
width: 900px;
height: 385px;
background-image: url(header.jpg);
}
.navbutton {
position: relative;
top: 310px;
width: 145px;
height: 75px;
margin-left: 0px;
margin-right: 5px;
background-image: url(link.png);
}
.navbutton a {
text-decoration:none;
}
.navbutton:hover{
background-image: url(linkselected.png);
}
You can fix this by adding the following rules:
//Change the header width to 901px to fit all the tabs
.header{
width: 901px;
height: 385px;
background-color: #ccc;
}
//Change the navbutton to be 146px wide
.navbutton {
position: relative;
top: 310px;
width: 146px;
height: 75px;
margin-left: 0px;
margin-right: 5px;
background-color: white;
}
//Remove the margin on the last child
.navbutton:last-child {
margin-right:0;
}
Here is the jsFiddle in case you need it - http://jsfiddle.net/XXczL/
place all the <li> tags in a <div>
set css for that <div id="customDiv">
#customDiv {
margin-left:auto;
margin-right:auto;
}
this will make the left and right margin equal and the extra space is distributed equally on both sides..
You have 2 problems going on here. First, you have margins being applied where you don't actually want them. Even when you correct this, your header's width still causes the appearance of the undesirable "space"
http://tinker.io/0191d/2
Include the following modifications:
.header {
width: 895px; /* or modify the width of the button elements */
}
ul {
margin: 0 0 0 -5px;
}
.navbutton {
margin-left: 5px;
margin-right: 0;
}
You could use the :last-child selector to remove the margin on the last element, but it doesn't work very well in instances where you actually want your elements to wrap (see: http://codepen.io/cimmanon/pen/dwbHi). Also, IE8 doesn't support it.
Check this jsfiddle for a fluid layout solution.
This solution uses the display: table, display: table-row, and display: table-cell property values.
Markup
<div class="header">
<div class="nav">
<ul>
<li class="navbutton">
About Us
</li>
<li class="navbutton">
Our Team
</li>
<li class="navbutton">
Education
</li>
<li class="navbutton">
Health Care
</li>
<li class="navbutton">
Advertising
</li>
<li class="navbutton">
Contact Us
</li>
</ul>
</div>
</div>
CSS
body{
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
.nav ul{
display: table-row;
list-style-type: none;
margin: 0;
padding: 0;
}
.header{
width: 900px;
height: 385px;
background: #f00 url(header.jpg);
overflow: hidden;
border: 1px solid #000
}
.nav{
display: table;
width: 100%;
margin-top: 310px;
}
.navbutton{
display: table-cell;
height: 75px;
background-image: url(link.png);
padding: 0 4px;
}
.navbutton a{
background: none repeat scroll 0 0 #FFFFCC;
color: #FF0000;
display: block;
height: 100%;
line-height: 75px;
text-decoration: none;
text-align: center;
}
.navbutton:hover{
background-image: url(linkselected.png);
}
li:last-child, li.the_last_child{ padding-right: 0; }
li:first-child, li.the_first_child{ padding-left: 0; }

align div's to bottom with margin applied

how can we align all the list items to the bottom of the parent separated by a margin.
If I apply position: absolute; bottom: 0, all elements align to the bottom but margins are discarded.
#bars0 {
width: 472px;
height: 258px;
position: relative;
}
#bars0 li {
border: solid red 1px;
width: 30px;
height: 50px;
margin-right: 95px;
position: absolute;
bottom: 0
}
<div id="bars0">
<ul><!-- update: added ul -->
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
Any reason why you can't surround the <li> with a <ul> tag and absolutely position the <ul>? That way you could control the margin of internal <li>??
The HTML:
<div id="bars0">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
The CSS:
#bars0 {
width: 472px;
height: 258px;
position: relative;
}
#bars0 ul {
position: absolute;
bottom: 0;
}
#bars0 li {
border: solid red 1px;
width: 30px;
height: 50px;
margin-right: 95px;
vertical-align: bottom;
display: block;
float: left;
}
#bars0 li:last-child {
margin-right: 0;
}
Thusly: http://jsfiddle.net/RYBFF/1/
To address your recent request on the comments: Just remove the margin from the last item in the list using :last-child on the <li> as shown above.
I think you're trying to do something like this:
<style type="text/css">
#container {
position: relative;
height:200px;
border:1px solid red;
}
#bars{
position:absolute;
bottom: 5px;
}
#bars ul li {
float: left;
min-width:100px;
}
</style>
<div id="container">
<div id="bars">
<ul>
<li>Test</li>
<li>Test 2</li>
</ul>
</div>
</div>
Here's a jsFiddle to demonstrate: http://jsfiddle.net/YYCZc/2/