Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > HTML, XHTML and CSS

Reply
 
LinkBack Thread Tools
Old September 3rd, 2008, 02:30 PM   #1
New Member
 

Join Date: Sep 2008
Location: London, Ontario, Canada
Age: 35
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Sacr1fyce is on a distinguished road
Lightbulb Centering CSS Menu

Hello all,

I am new to these forums and web design in general. I am trying to center a CSS menu on a template that I am testing out. I've tried a few things to no avail. Any pointers or advice, it would be greatly appreciated. Thanks,

Steve


Here is the CSS code:

Quote:
/* Menu */

#menuholder{background: #38424E; width: 100%; height: 25px; border-top: 1px solid #fff; border-bottom: 1px solid #fff;}

#nav {
width: 100%;
background: #38424E;
float: left;



}

#nav, #nav ul { /* all lists */
padding: 0;
margin: 0;
list-style: none;
line-height: 1;
}

#nav a {
display: block;
padding:6px 10px 7px 10px;
color: #fff;
width: auto;
}


#nav a:hover {
background: #fff;
color:#38424E;
}

#nav li { /* all list items */
float: left;
display: block;

}

#nav li ul { /* second-level lists */
position: absolute;
background: #38424E;
width: 165px;
left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
display: block;
}

#nav li ul a{ /* second-level lists */
width: 144px;
}

#nav li ul ul { /* third-and-above-level lists */
margin: -25px 0 0 155px;
padding: 0;
}

#nav li ul ul a{
width: 144px;
}

#nav li:hover, #nav li.hover {
position: static;
}

#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li.sfhover ul ul, #nav li.sfhover ul ul ul {
left: -999em;
}

#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul { /* lists nested under hovered list items */
left: auto;
}
Sacr1fyce is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 3rd, 2008, 03:45 PM   #2
Reputable Member
 

Join Date: Feb 2006
Location: $_home
Age: 21
Posts: 157
Thanks: 3
Thanked 2 Times in 2 Posts
Rep Altering Power: 0 Stormraven is an unknown quantity at this point
Re: Centering CSS Menu

Try this:

<div align="center">
[code here]
</div>
Stormraven is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 4th, 2008, 05:23 AM   #3
Aso
Most Reputable Member
 

Join Date: Oct 2007
Location: UK
Posts: 1,633
Blog Entries: 2
Thanks: 22
Thanked 84 Times in 79 Posts
Rep Altering Power: 0 Aso is on a distinguished road
Re: Centering CSS Menu

The problem is your floated <li>'s - unless you give the entire menu (<ul>) a fixed width, and add margin:0 auto, you won't be able to centre it.

If you require a fluid menu with no fixed-width, you can use Stu Nicholls' technique with display:table to centre it.
Aso is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old September 5th, 2008, 07:26 PM   #4
New Member
 

Join Date: Sep 2008
Location: London, Ontario, Canada
Age: 35
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Sacr1fyce is on a distinguished road
Re: Centering CSS Menu

Thanks for the replies! I will give the ideas a try.
Sacr1fyce is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
center , centering , css , menu


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Centering dropdown menu gribble HTML, XHTML and CSS 4 August 30th, 2007 12:10 PM
centering help please RZX Developer HTML, XHTML and CSS 7 August 2nd, 2007 07:58 AM
centering menu text escaflowne11 HTML, XHTML and CSS 3 September 30th, 2006 09:17 PM


Search Engine Optimization by vBSEO 3.2.0 RC8