我的文本导航栏一直向左拉,有人能告诉我我的代码是否有错吗?我试过内联块并删除了float,但它仍然不起作用!
#navigation ul {
list-style: none;
padding: 0;
width:400px;
margin:auto;
display: inline-block;}
#navigation li {
margin: 1em 1em;
font-family: Times New Roman, Times, Calibri, GillSans, sans-serif;
font-style: italic;
display: inline-block;}
#navigation li a {
text-decoration: none;
display: inline-block;
}
#content {
width: 960px;
margin-top: 25px;
text-align:center;
}
#footer {
margin-top:30px;
text-align: center;
font-size: 0.9em;
}
#sub_navigation {
color: #BBB;
text-align:center;
margin-bottom: 25px;
height:55px;
letter-spacing:5px;
}
我的HTML是:
<div id="navigation" class="span-24 last">
<ul>
<li><a href="about.html">About</a></li>
<li><a href="editorial.html">Editorial</a></li>
<li><a href="portraits.html">Portraits</a></li>
只需删除ul
的display:inline-block
属性即可将其居中:对于项目,添加text-align
#navigation ul {
list-style: none;
padding: 0;
width:400px;
margin:auto;
/*display: inline-block;*/ ---> Remove this
text-align: center; ----> Add this
}
演示http://jsfiddle.net/aYVAP/2/
删除显示:--->中的内联块
#navigation li a {
text-decoration: none;
**display: inline-block;**
}
粘贴:text-align:center;