|
|
 |
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
|
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;
}
|
|
|
|
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
|
Re: Centering CSS Menu
Try this:
<div align="center">
[code here]
</div>
|
|
|
September 4th, 2008, 05:23 AM
|
#3
|
|
Most Reputable Member
Join Date: Oct 2007
Location: UK
Posts: 1,633
Thanks: 22
Thanked 84 Times in 79 Posts
Rep Altering Power: 0
|
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.
|
|
|
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
|
Re: Centering CSS Menu
Thanks for the replies! I will give the ideas a try.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|