【发布时间】:2014-06-18 20:07:40
【问题描述】:
我的链接无法在页面中间居中。我试过 text-align: center;在我可以在样式表中的几乎所有地方都无济于事。 http://www.ddofans.org/
这里是相关的代码条:
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>
还有 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%;
}
【问题讨论】:
-
text-align:middle 应该是
text-align:center而不是浮动你的 li,而是让它们display:inline-block
标签: html css navigation center