Click to See Complete Forum and Search --> : How to center my ul?
1234567890
06-17-2009, 10:50 AM
I have a nav menu you can see here:
http://mibsolutionsllc.com/payne/
I am having issues centering the blocks. So instead of having them start on the left, start in the center. I cannot find an easy answer, any CSS gurus out there can help me out? I am sure it's an easy answer.
cbVision
06-17-2009, 02:37 PM
Here's your css for the menu
#menu {
margin:0 0 10px 0;
padding:0;
list-style-type:none;
float:left;
width:100%;
background: #E2E3E4;
}
I would try removing the float:left;
1234567890
06-17-2009, 04:21 PM
That does nothing.
skilled1
06-17-2009, 05:00 PM
remove the float and add align:center;
1234567890
06-17-2009, 06:02 PM
For #menu, align: center or text-align: center does nothing.
PierceMoore
06-18-2009, 03:17 AM
Have you tried using "text-align:center" on the parent element?
WebWarrior
06-18-2009, 03:59 AM
You must remove the float property from both #menu and #nav.
You also need to set the width of the object you wish to center, which in this case is #nav. The sample code below illustrates how it can be done.
You might want to experiment with a different width (instead of 91%) to suit your needs.
#menu
{
background-color: #E2E3E4;
height: 50px;
}
#nav
{
list-style: none;
margin: 0 auto; /* center aligns fixed-width element */
width: 91%; /* Fixed width must be used */
}
#nav li
{
float: left;
}
#nav li a
{
display: block;
background-color: #9E9F9F;
text-decoration: none;
padding: 5px 15px;
margin-right: 10px;
float: left;
}
David Harrison
06-21-2009, 08:31 AM
You will not be able to centre elements that are floated to either side. Instead, you can set display:inline; on the <li>s and set text-align:center; on the <ul>. Also, you can get rid of those <span> elements while you're at it, the padding can easily be applied to the links themselves.