WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts



WeLoveCSS > WEB DESIGN > CSS > Horizontal Navigation Bar: Can't center ?!?!

Reply
  Thread Tools Display Modes
Old 3rd August 11, 12:22 PM   #1
acekicker77
WLC Member
 
Join Date: Jul 2011
Location: London
Posts: 14
Default Horizontal Navigation Bar: Can't center ?!?!

Guys,

Having a problem centering this horizontal navigation bar. The navigation bar is contained within a box #hnav-box. As you can see the list items are not centered in this box.

How do I get around this? www.mauricegreenland.com

Code:
#hnav-box {
	width: 800px;
	border: 1px solid #000;
	float: left;
	}
/**********************************************/
/* START styles for horizontal navigation bar**/
/**********************************************/
Code:
ul {
	margin: 0;
	padding: 0;
	text-decoration: none; 
	list-style-type: none;
	text-align: center;
	}
Code:
li { 
	float: right;
	}
Code:
 a {
	text-decoration: none;
	color: #2E0854;
	display: block;
	width: 100px;
	margin-right: 5px;
	padding: 1x;
	}
Code:
a:hover {
	text-decoration: none;
	background-color: #2E0854;
	color: #fff;
	}
acekicker77 is offline   Reply With Quote
Old 3rd August 11, 03:38 PM   #2
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
Default Re: Horizontal Navigation Bar: Can't center ?!?!

Try this method (Just study the source code): http://www.css-lab.com/demos/nav/cntrd-floats.html (Link compliments of user: Rayzur)
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Old 3rd August 11, 04:18 PM   #3
acekicker77
WLC Member
 
Join Date: Jul 2011
Location: London
Posts: 14
Default Re: Horizontal Navigation Bar: Can't center ?!?!

Thanks tried that, still could not get it ul to center in the #hnav-box

When I used the previous technique the ul would float oustide of the #hnav-box.
acekicker77 is offline   Reply With Quote
Old 3rd August 11, 04:52 PM   #4
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
Default Re: Horizontal Navigation Bar: Can't center ?!?!

If it's going outside of the designated area, then you're skipping the step that brings it back in, and centers it.
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Old 3rd August 11, 04:55 PM   #5
acekicker77
WLC Member
 
Join Date: Jul 2011
Location: London
Posts: 14
Default Re: Horizontal Navigation Bar: Can't center ?!?!

Quote:
Originally Posted by meesa View Post
If it's going outside of the designated area, then you're skipping the step that brings it back in, and centers it.
ok i'll try again and show you the css once I'm done
acekicker77 is offline   Reply With Quote
Old 3rd August 11, 10:01 PM   #6
acekicker77
WLC Member
 
Join Date: Jul 2011
Location: London
Posts: 14
Default Re: Horizontal Navigation Bar: Can't center ?!?!

Tried it again, failed!

#nav is all the way out to the right

ul, l, a appear to be floating left in #hnav-box (i think)

Any ideas?

CSS:
Code:
#header {
	width: 920px;
	margin: 0 auto;
	border: 1px solid #333;
	overflow: hidden;
	}
	
#wrapper {
	width: 920px;
	margin: 0 auto;
	border: 1px solid #000;
	}
	
#content {
	width: 820px;
	margin: 0 auto 20px;
	border: 1px solid red;
	padding: 10px;
	}
	
#c-box {
	width: 700px;
	margin: 30px auto 0;
	border: 1px dotted blue;
	padding-left: 5px;
	}
#footer {
	width: 920px;
	margin: 0 auto;
	border: 1px solid #333;
	}

/*describes styles for container around the horizontal navigation bar*/	
	
#hnav-box {
	width: 800px;
	border: 1px solid #000;
	float: left;
	clear: both;
	overflow: hidden;
		}

#nav {
	width: 800px;
	border: 1px solid blue;
	overflow: hidden;
position:relative;
left:50%;
}
	
		/**********************************************/
		/* START styles for horizontal navigation bar**/
		/**********************************************/
#hnav-box ul {
	margin: 0;
	padding: 0; /*Set padding and margin to 0 to remove browser defaults*/
	text-decoration: none; /*Removes the bullets. Horizontal Navigations bars dont need list markers*/
	list-style-type: none;
	text-align: center;
position:relative;
left:-50%;
	}
	
#hnav-box li { 
	float: left;			/* list items can be displayed horizontal using either float or inline. if you want the list items to be equal length, use float*/
	}						
	
#hnav-box li a {
	text-decoration: none;
	color: #2E0854;
	display: block;			/*Displaying as block makes the whole link area clickable not just the text. Also alows us to specify the width*/
	width: 100px;			/*width of each link*/
	margin-right: 5px;
	padding: 1x;
	}
	
#hnav-box li a:hover {
	text-decoration: none;
	background-color: #2E0854;
	color: #fff;
	}
HTML:
Code:
<body>
<a name="top"></a>

	<div id="header">
header
	</div><!--Close #header-->

	<div id="wrapper">
wrapper

	<div id="content">
		<div id="hnav-box"><!-- Contains #hnav -->
        <div id="nav">
<ul>
<li><a href="#">Contact Us</a></li>
<li><a href="#">Photo Gallery</a></li>
<li><a href="#itinerary">Our Itinerary</a></li>
<li><a href="#accommodation">Accommodation</a></li>
<li><a href="#guestinfo">Guest Info</a></li>
<li><a href="#venue">The Venue</a></li>
<li><a href="#">Home</a></li>

</ul>
		</div><!--Close #nav-->		
		</div><!--Close #hnav-box-->
acekicker77 is offline   Reply With Quote
Old 3rd August 11, 10:16 PM   #7
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,134
Default Re: Horizontal Navigation Bar: Can't center ?!?!

It looks like your missing a few float styles.
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Old 4th August 11, 09:01 AM   #8
acekicker77
WLC Member
 
Join Date: Jul 2011
Location: London
Posts: 14
Default Re: Horizontal Navigation Bar: Can't center ?!?!

Gave up! :-) Decided to "fake it" by adjusting widths of list items
acekicker77 is offline   Reply With Quote
Reply


Thread Tools
Display Modes
Linear Mode Linear Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:00 PM.



Home | Advertise | Contact Us | Top
Home | Advertise | Contact Us | Top

Copyright© 2006 WeLoveCSS.com. All Rights Reserved.
Powered by vBulletin Version 3.8.4 Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.