Try this:
#nav {
background: #035ea3;
width: auto;
text-align: center;
}
#nav ul {
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: inline-block;
zoom: 1;
}
Domanda
I can't get my links centered in the middle of the page. I've tried text-align: center; in just about every place I can in my style sheet to no avail. http://www.ddofans.org/
Here the relevant code strip:
HTML:
<div id='nav'>
<ul>
<li class='active'><a href='index.html'><span>Home</span></a></li>
<li><a href='#'><span>Blog</span></a></li>
<li><a href='#'><span>News</span></a></li>
<li class='last'><a href='#'><span>Other</span></a></li>
</ul>
</div>
And the CSS:
#nav {
background: #035ea3;
width: auto;
text-align: middle;
}
#nav ul {
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: block;
zoom: 1;
}
#nav ul:after {
content: ' ';
display: block;
font-size: 0;
height: 0;
clear: both;
visibility: hidden;
}
#nav ul li {
float: left;
display: block;
padding: 0;
}
#nav ul li a {
color: #f5f5f5;
text-decoration: none;
display: block;
padding: 15px 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
position: relative;
-webkit-transition: color .25s;
-moz-transition: color .25s;
-ms-transition: color .25s;
-o-transition: color .25s;
transition: color .25s;
}
#nav ul li a:hover {
color: #000000;
}
#nav ul li a:hover:before {
width: 100%;
}
#nav ul li a:after {
content: '';
display: block;
position: absolute;
right: -3px;
top: 19px;
height: 6px;
width: 6px;
background: #f5f5f5;
opacity: .5;
}
#nav ul li a:before {
content: '';
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 0;
background: #000000;
-webkit-transition: width .25s;
-moz-transition: width .25s;
-ms-transition: width .25s;
-o-transition: width .25s;
transition: width .25s;
}
#nav ul li.last > a:after,
#nav ul li:last-child > a:after {
display: none;
}
#nav ul li.active a {
color: #000000;
}
#nav ul li.active a:before {
width: 100%;
}
Soluzione
Try this:
#nav {
background: #035ea3;
width: auto;
text-align: center;
}
#nav ul {
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: inline-block;
zoom: 1;
}
Altri suggerimenti
Give display: inline-block;
to #nav ul
& text-align:center
to #nav
You are currently using text-align:middle
in #nav
which is wrong.
You need to wrap you nav in a container and then make your navbar center by specifying a margin.
your nav style should be:
#nav {
background: #035EA3;
width: 500px;
margin: 0 auto;
}
and your html would look something like this:
<div style="width: 100%;background-color: #035EA3;">
<div id="nav">
<ul>
<li class="active"><a href="index.html"><span>Home</span></a></li>
<li><a href="#"><span>Blog</span></a></li>
<li><a href="#"><span>News</span></a></li>
<li class="last"><a href="#"><span>Other</span></a></li>
</ul>
</div>
</div>
Change text-align: middle;
to text-align: center;
of #nav &
display: block;
to display: inline-block;
of #nav ul