So I have the following CSS in place to display a horizontal navigation bar using:
.navigation ul {
list-style: none;
padding: 0;
margin: 0;
}
.naviga
ul {
display: inline-block;
text-align: center;
}
.navigation ul
{
list-style-type: none;
padding: 0px;
width: 200px;
margin: 0 auto;
}
style="position: absolute; z-index: 1;"
Give your .navigation ul a width and use margin:0 auto;
.navigation ul
{
list-style: none;
padding: 0;
width: 400px;
margin: 0 auto;
}
You could set the <li>
's to be display: inline
, then set text-align: center
on the <ul>
. Doing that, you can remove the float: left
from the list items and you don't need to have a fixed width for the navigation bar as you would if you used margin: 0 auto
.
<html>
<head>
<style>
ul {
list-style: none;
text-align: center;
}
li {
display: inline;
margin: 0 1.15em;
}
</style>
</head>
<body>
<ul>
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</body>
</html>
Well, to use margin:0 auto
on something, it must have a defined width. Probably the best workaround is:
ul li {
display: inline;
list-style-type: none;
}
ul {
text-align:center;
}