I am having a terrible time creating a CSS horizontal menu where the items are fixed width yet the entire menu can center. Can any one help?
Here is an example http://www.highfivefriday.com/test.html
Here is the code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" href="test.css" rel="stylesheet">
<title>Please Help :)</title>
<style type="text/css">
<!--
/**********************/
/* Menu Layout */
/**********************/
#container{
width:800px;
background-color:#e0e0e0;
}
#inner_menu{
margin: 10px auto;
padding:0;
list-style:none;
}
#inner_menu li{
margin:0;
padding:0;
display:inline;
}
#inner_menu li a, #inner_menu li a:visited{
padding:5px;
background-color:#23185d;
border-color:#000000;
border-width:1px;
border-style:solid;
color:#FFFFFF;
text-decoration:none;
}
#inner_menu li a:hover{
background-color:#2070bd;
}
/**************************************/
/* Menu Layout TRYING TO CENTER */
/**************************************/
#inner_menu2 li a:hover{
background-color:#2070bd;
}
#inner_menu2{
margin: 10px auto;
padding:0;
list-style:none;
}
#inner_menu2 li{
margin:0;
padding:0;
display:inline;
}
#inner_menu2 li a, #inner_menu2 li a:visited{
display:block;
width:150px;
float:left;
padding:5px;
background-color:#23185d;
border-color:#000000;
border-width:1px;
border-style:solid;
color:#FFFFFF;
text-decoration:none;
}
#inner_menu2 li a:hover{
background-color:#2070bd;
}
-->
</style>
</head>
<body>
<div id="container">
<P>The menu below should appear centered, but I need the items to be a fixed width (150px) because I want to use a background image. </p>
<div align="center">
<div id="inner_menu">
<ul>
<li><a href="#">Button 1</a></li>
<li><a href="#">Button 2</a></li>
<li><a href="#">Button 3</a></li>
</ul>
</div>
</div>
<P>When I set either the <li> or <a> tags to a fixed width they no longer are side by side. So I do a float:left; and they go side by side but the menu will not center. As you can see below.</p>
<div align="center">
<div id="inner_menu2">
<ul>
<li><a href="#">Button 1</a></li>
<li><a href="#">Button 2</a></li>
<li><a href="#">Button 3</a></li>
</ul>
</div>
</div>
<div style="clear:both;"></div>
<p>Any suggestions?</p>
<div>
</body>
</html>
I have attached this file in case anyone feels so motivated to play.
Any suggestions are appreciated!