Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello :).

I have a test page which has a menu on it. I would like to keep the menu at the center of this page. Here is the menu's CSS code:

.menu { 
	height: 45px;
	display: block;
}
.menu ul {
	list-style: none;
	padding: 0;
}
.menu ul li {
	float: left;
	overflow: hidden;
	position: relative;
	text-align: center;
	line-height: 45px;
}
.menu ul li a {
	position: relative;
	display: block;
	width: 110px;
	height: 45px;
	font-family: Arial;
	font-size: 11px;
	font-weight: bold;
	letter-spacing: 1px;
	text-transform: uppercase;
	text-decoration: none;
	cursor: pointer;
}
.menu ul li a span {
	position: absolute;
	left: 0;
	width: 110px;
}
.menu ul li a span.out {
	top: 0px;
}
.menu ul li a span.over,
.menu ul li a span.bg { 
	top: -45px;
}
#menu2 {
	background: #000;	
	margin: auto;
}
#menu2 ul li a {
	color: #FFF;
}
#menu2 ul li a span.over {
	background: #FFF;
	color: #000;
}

The HTML code is a simple ul/li code block. Please tell me of how can I centerize the menu? Please respond ASAP.
Posted
Updated 14-Jun-10 4:50am
v2
Comments
Ankur\m/ 15-Jun-10 8:54am    
Andrecito777 wrote: "lol thats what I did try to try to test that thing :0 Thanks though".
So it worked?

 
Share this answer
 
Comments
Andrecito777 14-Jun-10 22:46pm    
no It didn't work. Anyways, my div already has a class. Thanks though
Try putting the menu inside a div and align the div to the center. I guess this should work.
 
Share this answer
 
Comments
Andrecito777 15-Jun-10 8:36am    
lol thats what I did try to try to test that thing :0 Thanks though
Hey Tyr this Out....Hope it will be helpful!!!
This is another example--->


CSS
#centeredmenu
    { float:left;
      width:100%;
      background:#fff;
      border-bottom:4px solid #000;
      overflow:hidden;
       position:relative;
    }


 #centeredmenu ul
    {
       clear:left;
       float:left;
       list-style:none;
       margin:0;
       padding:0;
       position:relative;
       left:50%;
       text-align:center;
   }

  #centeredmenu ul li
    {
       display:block;
       float:left;
       list-style:none;
        margin:0;
        padding:0;
         position:relative;
          right:50%;
    }

   #centeredmenu ul li a
    {
       display:block;
       margin:0 0 0 1px;
       padding:3px 10px;
       background:#ddd;
       color:#000;
       text-decoration:none;
       line-height:1.3em;
    }

    #centeredmenu ul li a:hover
    {
        background:#369;
        color:#fff;
    }

    #centeredmenu ul li a.active, #centeredmenu ul li a.active:hover
    {
        color:#fff;
        background:#000;
        font-weight:bold;

    }
 
Share this answer
 
Comments
Andrecito777 15-Jun-10 8:43am    
sorry but no :( It made the menu MESSED up lol. Its was horribly weird but thanks for trying.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900