想要在bootstrap中居导航栏

时间:2017-02-14 18:35:39

标签: html twitter-bootstrap css3

这是我的代码,我尝试了很多东西,帮助我Obiwan!我试着做一个容器标签,对css的响应。

<!DOCTYPE html>
<html lang="en">

<head>
  <!-- This sets up bootstrap 3-->
  <meta charset="utf-8">
  <meta name="veiwport" content="width-device-width, initial-scale-1">
  <!-- this sets initial zoom when page is loaded -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <!-- links css -->
</head>

<body>
  <div class="container">
    <nav class="navbar navbar-default">
      <div class="container-fluid">

        <div class="navbar-header">
          <a class="navbar-brand" href="#">Lauren Neely</a>
        </div>

        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home</a>
          </li>
          <li><a href="#">Gallery</a>
          </li>
          <li><a href="#">Sketchbook + Misc</a>
          </li>
          <li><a href="#">Contact</a>
          </li>
        </ul>

      </div>
    </nav>
  </div>

</body>

</html>

1 个答案:

答案 0 :(得分:0)

您可以添加css:

@media (min-width: 768px){
   .navbar-nav{
     text-align:center;
     float:none;
   }
   .navbar-nav li{
     float:none;
     display:inline-block;
   }
}

float: none您将.navbar-nav

设置为中心对齐

并设置@media (min-width: 768px)您只能将这些规则应用于桌面和平板电脑视图。对于移动自举手柄导航栏的响应方式,所以没有必要。

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">

<head>
  <!-- This sets up bootstrap 3-->
  <meta charset="utf-8">
  <meta name="viewport" content="width-device-width, initial-scale-1">
  <!-- this sets initial zoom when page is loaded -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <!-- links css -->
<style>
@media (min-width: 768px)
    .navbar-nav{
      text-align:center;
      float:none;
    }
   .navbar-nav li{
      float:none;
      display:inline-block;
    }
}

</style>
</head>

<body>
  <div class="container">
    <nav class="navbar navbar-default">
      <div class="container-fluid">

        <div class="navbar-header">
          <a class="navbar-brand" href="#">Lauren Neely</a>
        </div>

        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home</a>
          </li>
          <li><a href="#">Gallery</a>
          </li>
          <li><a href="#">Sketchbook + Misc</a>
          </li>
          <li><a href="#">Contact</a>
          </li>
        </ul>

      </div>
    </nav>
  </div>

</body>

</html>
&#13;
&#13;
&#13;