html - 导航栏元素对齐

标签 html css twitter-bootstrap

我正在构建一个网站,我在导航栏中遇到了导航栏元素未居中对齐的问题

HTML 和 CSS 代码:

<nav class="navbar navbar-inverse">
  <div class="container">
    <ul id="navigation" class="nav navbar-nav">
      <li class="active"> <a href="#"> Home    </a></li>
      <li><a href="#"> Marketing Services </a> </li>
      <li> <a href="#"> IT Management Services </a> </li>
      <li> <a href="#"> Molex Portfolio  </a> </li>
      <li> <a href="#"> Contact Us </a> </li>
      <li> <a href="#"> Employement Opportunities </a> </li>
    </ul>
  </div>
</nav>

我的CSS代码是

body{
    background-repeat:no-repeat;
    background-position: top right;
    background-attachment: fixed;
}

h1{
    margin:1px ;
    color:red !important;
    text-align:center;
}

hr{
    border-color:red !important;
    width:50%;
}

a {
  padding: 0px 10px;      
}

#navigation{
    text-align:center!important;
    display: inline-block!important;
    margin: auto;
}

最佳答案

您正尝试将 ul 居中于 inline-block 样式,请尝试将其更改为 block

body{

    background-repeat:no-repeat;
    background-position: top right;
    background-attachment: fixed;
}
h1{
    margin:1px ;
    color:red !important;
    text-align:center;
}
hr{
    border-color:red !important;
    width:50%;
}
a {
  padding: 0px 10px;

}
#navigation {
    text-align:center!important;
    display: block!important;
    margin: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-inverse">
            <div class="container">
                <ul id="navigation" class="nav navbar-nav">
                    <li class="active"> <a href="#"> Home    </a></li>
                    <li><a href="#"> Marketing Services </a> </li>
                    <li> <a href="#"> IT Management Services </a> </li>
                    <li> <a href="#"> Molex Portfolio  </a> </li>
                    <li> <a href="#"> Contact Us </a> </li>
                    <li> <a href="#"> Employement Opportunities </a> </li>

                </ul>

            </div>

        </nav>

关于html - 导航栏元素对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38184535/

相关文章:

html - Bootstrap 折叠标题在第一次点击时闪烁

jquery - Bootstrap 中的 3 级下拉菜单

javascript - 如何在编号列表中引用特定元素编号?

html - CSS 彼此相邻对齐,烦人的边框应该只适用于一个 div

php - PHP/HTML Web 应用程序中的全局计数器变量

html - 当浏览器缩小时,如何正确对齐两个相互折叠的 div?

css - joomla 3.3.0 从 2.5.20 升级未在模板中获取 css

html - Flex/Grid 布局不适用于按钮或字段集元素

html - 为什么我的移动网站没有居中对齐?

javascript - 使用jquery设置下拉列表中第一个选项的值