在Bootstrap中扩展Navbar-Right的宽度

时间:2016-10-07 19:36:17

标签: html css twitter-bootstrap navigation nav

我在Bootstrap中扩展导航栏时遇到问题。我需要它来适应它的所有元素。以下是发生的事情:

我无法单独显示个人资料图片和用户名。我已经尝试过清楚了:两个"和正常的东西。当我扩展UL的大小时,它会破坏父DIV。当我尝试扩展LI的大小时,它没有做任何事情。这是我的代码:

<!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#"><img src="images/logo.png" class="logo"> <span class="site-title">Privy Personal</span></a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li><a href="#">Files</a></li>
            <li class="active"><a href="#">Sharing</a></li>
            <li><a href="#contact">Recent</a></li>
              <li><a href="#">Deleted</a></li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#"><img src="images/Search.svg"> </a></li>
            <li><a href="#"><img src="images/Notification.svg"> </a></li>
            <li><a href="#"><span class="username">Tony Stark</span><img src="http://placehold.it/25x25" class="profile"></a></li>
          </ul>
        </div><!--/.nav-collapse -->
    </nav> <!-- End Fixed Nav -->

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

<div class="container-fluid">之后添加<nav>,并使用保证金调整名称和图片对齐方式。

试试这个

检查演示here

HTML:

<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
      <a class="navbar-brand" href="#"><span class="site-title">Privy Personal</span></a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li><a href="#">Files</a></li>
        <li class="active"><a href="#">Sharing</a></li>
        <li><a href="#contact">Recent</a></li>
        <li><a href="#">Deleted</a></li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#"><i class="fa fa-user"></i> </a></li>
        <li><a href="#"><i class="fa fa-user"></i> </a></li>
        <li><a href="#"><span class="username">Tony Stark</span><img src="http://placehold.it/25x25" class="profile img-circle"></a></li>
      </ul>
    </div>
    <!--/.nav-collapse -->
  </div>
</nav>
<!-- End Fixed Nav -->

CSS:

.username {
  margin-right: 5px;
}

.profile {
  margin-top: -7px;
}

我希望它可以帮助你:)