html - 如何使用 CSS 将文本导航栏居中

标签 html css text navigation

我的文本导航栏一直向左拉,谁能告诉我是不是我的代码哪里有问题?我试过 inline-block 并删除了 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>

最佳答案

只需删除 uldisplay: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/

关于html - 如何使用 CSS 将文本导航栏居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20219827/

相关文章:

javascript - 为什么 data-amp-bind-href 或 [href] 在 amp-bind 组件中不起作用?

html - header 对齐问题 - 无法修复

javascript - Framework7 和 Material Design : Styling not rendered

html - 如何使 CSS3 圆 Angular 在 Chrome/Opera 中 overflow hidden

javascript - 如何确保预加载器覆盖整个高度并且没有可见的加载页面元素?

Android EditText 宽度因为提示

css - 为什么文本颜色属性称为 'color' ?

html - 三个 div 以百分比高度跨越整个页面(全长和全宽)

c - 从文本文件中读取数字并将其用作输入

javascript - 复制/b 除两个之外的所有类型的文件