Hi guys, I've gone through many websites trying to find a solution. Since I'm not that good with css (just started learning) i've failed to get it to work. I have a simple css menu that i've been trying to center for hours now:( could somebody help me out and give me an opportunity to learn from you I'd really appreciate it. Thank you in advance.

css

#container {
	width:800px;
	margin:0 auto;
	padding:0;
	background-color: #CCC;
}
#footer
{
clear:both;	
}
/* ### MENU ### */
#adminmenu
{
width:100%;	
}
ul {
	position:relative;
	font-family: Arial, Verdana;
	font-size: 14px;
	margin: 0;
	padding: 0;
	list-style: none;
	text-align: center;
	
}
ul li {
	display: block;
	position: relative;
	float: left;
}
li ul {
	display: none;
}
ul li a {
	display: block;
	text-decoration: none;
	color: #ffffff;
	border-top: 1px solid #ffffff;
	padding: 5px 15px 5px 15px;
	background: #2C5463;
	margin-left: 1px;
	white-space: nowrap;
}
ul li a:hover {
	background: #617F8A;
}
li:hover ul {
	display: block;
	position: absolute;
}
li:hover li {
	float: none;
	font-size: 11px;
}
li:hover a {
	background: #617F8A;
}
li:hover li a:hover {
	background: #95A9B1;
}
/* ### END MENU ### */

HTML

<body>
<div id="container">
Admin Panel
<div id="adminmenu">
<ul>
          <li><a href="index.php">Main Menu</a></li>
          <li><a href="menu2.php">Menu2</a></li>
          <li><a href="menu3.php">Menu3</a>
            <ul>
              <li><a href="menu4.php">menu4</a></li>
              <li><a href="menu5.php">menu5</a></li>
            </ul>
    </li>
    
  </ul>
  </div>
  <div id="footer">Footer</div>
</div>

</body>

I don't know what do you want to center, text or element. If you want to center the text, try this:

#
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;/* white-space ignore text-align property, you should remove */
text-align: center
}

I don't know what do you want to center, text or element. If you want to center the text, try this:

#
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #2C5463;
margin-left: 1px;
white-space: nowrap;/* white-space ignore text-align property, you should remove */
text-align: center
}

Hi thx for your reply but i already have text center. I wanna center the menu itself.

Problem solved!

#container {
	width:800px;
	margin:0 auto;
	padding:0;
	background-color: #CCC;
}
#footer {
	clear:both;
}
/* ### MENU ### */
#adminmenu {
	position:relative;
	width:750px;
	left:50%;
	margin-left:-375px;
	height:25px;
}
ul {
	position:relative;
	font-family: Arial, Verdana;
	font-size: 14px;
	margin: 0;
	padding: 0;
	list-style: none;
	text-align: center;
}
ul li {
	display: block;
	position: relative;
	float: left;
	width:150px;
}
li ul {
	display: none;
}
ul li a {
	display: block;
	text-decoration: none;
	color: #ffffff;
	border-top: 1px solid #ffffff;
	padding: 5px 15px 5px 15px;
	background: #2C5463;
	margin-left: 1px;
	white-space: nowrap;
}
ul li a:hover {
	background: #617F8A;
}
li:hover ul {
	display: block;
	position: absolute;
}
li:hover li {
	float: none;
	font-size: 11px;
}
li:hover a {
	background: #617F8A;
}
li:hover li a:hover {
	background: #95A9B1;
}
/* ### END MENU ### */
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.