Using the following CSS, I’m trying to make a navigation bar at the top of the page (fixed to the top) but instead of it being on the absolute left of the screen, I want it centered.
ul#list-nav
{
position:fixed;
top:0;
left:0;
margin:auto;
padding:0px;
width:100%;
height:28px;
font-size:120%;
display:inline;
text-decoration:none;
list-style:none;
background-color: #1F1F1F;
border:none;
z-index:1000;
}
ul#list-nav li
{
float:left;
}
ul#list-nav a
{
background-color:#1F1F1F;
color:#C4C4C4;
/*display:block;*/
padding:5px 15px;
text-align: center;
text-decoration:none;
font-size:14px;
}
ul#list-nav a:hover
{
background-color:#4D4D4D;
text-decoration:none;
}
ul#list-nav a:active
{
background-color:#9C9C9C;
text-decoration:none;
}
Attempts so far make it a vertical list, or make the buttons start in the center (rather than be centered). How can I accomplish this?
EDIT: below is the HTML … this list is the only thing being styled.
<ul id="list-nav">
<li><a href="/ourbs/index.php">Home</a></li>
<li><a href="/ourbs/categories/projects.php">Projects</a></li>
<li><a href="/ourbs/categories/opinion.php">Opinion</a></li>
<li><a href="/ourbs/categories/humour.php">Humour</a></li>
<li><a href="/ourbs/categories/games.php">Games</a></li>
<li><a href="/ourbs/categories/movies.php">Movies</a></li>
<li><a href="/ourbs/categories/tvshows.php">TV Shows</a></li>
</ul>
EDIT2: here’s a jsFiddle if this helps
http://jsfiddle.net/752jU/1/
You only need one wrapper
divto accomplish this…http://jsfiddle.net/752jU/5/
Note: By using
display: inlinemy answer is also good in IE 6 & 7, if that matters.CSS:
HTML: