使Navbar内容居中

时间:2016-11-05 15:17:06

标签: html css

有人可以帮助我将链接放在我的导航栏上。我一直在尝试最后45分钟。

每次我使用display:flex和justify-content:center它都会起作用,直到汉堡包按钮出现并被点击然后全部浮动到左边。

任何帮助都会受到大力赞赏。

谢谢

里斯



.navbar {
  background-color: #000;
  justify-content: center;
  height: auto;
  font-family: Gill Sans, Verdana;
  font-size: 15px;
  line-height: 18px;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: bold;
}
nav li:hover {
  background-color: #C00;
  margin: 0;
}

<nav>
  <div class="navbar-container">
    <!--NAVBAR CONTAINER START -->
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-header">
        <button aria-controls="navbar" aria-expanded="false" class="navbar-toggle" data-target="#navbar" data-toggle="collapse" type="button">

          <span class="icon-bar"></span> 
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#"></a>

      </div>

      <div class="navbar-collapse collapse" id="navbar">
        <ul class="nav navbar-nav">
          <li class="active">
            <a href="#header-container"><strong>HOME</strong></a>
          </li>


          <li>
            <a href="#meettheband-container"><strong>MEET THE BAND</strong></a>
          </li>


          <li>
            <a href="#photo-container"><strong>PHOTOS</strong></a>
          </li>


          <li>
            <a href="#video-container"><strong>VIDEOS</strong></a>
          </li>


          <li>
            <a href="#getintouch-container"><strong>GET IN TOUCH</strong></a>
          </li>
        </ul>
      </div>

  </div>
  <!-- NAVBAR CONTAINER END -->
  </nav>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:1)

查看此笔http://codepen.io/Danstan/pen/ENajRb,链接将位于中心

ul.nav.navbar-nav {
display: table;
margin: 0 auto;
float: none !important;

}

答案 1 :(得分:0)

.navbar {
  background-color: #000;

  height: auto;
  font-family: Gill Sans, Verdana;
  font-size: 15px;
  line-height: 18px;
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: bold;
  text-align:center;
}

.navbar .navbar-header {
   display:table;
   width:auto;
   margin:auto;
}

nav li:hover {
  background-color: #C00;
  margin: 0;
}

答案 2 :(得分:0)

试试这个: -

    /* Center Nav Bar */
    #nav ul {
 text-align: center; 
} 

链路: - http://themes.typepad.com/guide/2011/12/navbar-center.html