left, right & centering content inside a bootstrap navbar

岁酱吖の 提交于 2020-01-11 13:06:12

问题


trying to get a bootstrap navbar to have links on the left, center and right side on a responsive website.

is this even possible? maybe navbar-justified is wrong to center content on the navbar?

 <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <ul class="nav navbar-nav navbar-left">
            <a class="navbar-brand" href="#home"> LEFT </a>
          </ul>
          <ul class="nav navbar-nav navbar-justified">
            <a href="#"> CENTER </a>
          </ul>
          <ul class="nav navbar-nav navbar-right">
          <li>
            <a href="#facebook"> <img src="fb.png" class="fb"> RIGHT </a>
          </li>
        </ul>
      </div>
    </nav>

回答1:


You can use the the navbar-left/navar-right classes to position your links and a custom class to position the navbar-brand according to the size you need it to be. See working example Snippet.

.navbar-custom .navbar-brand.navbar-brand-centered {
  position: absolute;
  left: 50%;
  display: block;
  width: 200px;
  text-align: center;
  top: 0;
}
.navbar.navbar-custom > .container .navbar-brand.navbar-brand-centered,
.navbar.navbar-custom > .container-fluid .navbar-brand.navbar-brand-centered {
  margin-left: -100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-default navbar-custom" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#js-navbar-collapse"> <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>

      </button>
    </div> <a class="navbar-brand navbar-brand-centered" href="#/">Brand</a>

    <div class="collapse navbar-collapse" id="js-navbar-collapse">
      <ul class="nav navbar-nav navbar-left">
        <li><a href="#/">Link</a>

        </li>
        <li><a href="#">Link</a>

        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#">Link</a>

        </li>
        <li><a href="#">Link</a>

        </li>
      </ul>
    </div>
  </div>
</div>
<div class="container">
  <div class="well">Yup</div>
</div>


来源:https://stackoverflow.com/questions/33226509/left-right-centering-content-inside-a-bootstrap-navbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!