Bootstrap Nav项目不会向右浮动

时间:2018-01-21 23:27:06

标签: html css twitter-bootstrap bootstrap-4

我一直试图让我的ul中的导航项正确浮动。我尝试了很多不同的东西,包括这个彻底答案中的所有内容:  Bootstrap 4 align navbar item to the right

导航项目仍然卡在左侧。

在这一点上,我觉得我错过了一些明显的东西?包含列表项的div类是新添加的,并且就我所知的情况而言似乎对列表项的行为没有任何影响。我尝试过的所有东西都没有这些div标签,仅供参考。

好奇是否有人能在这里看到问题?

    .navbar-default {
      background-color: white;
    }
    
    .navbar {
      display: flex;
      min-height: 50px;
      border-bottom: 1px solid black;
      align-items: center;
      margin-bottom: 0;
    }
    
    
    .profile-dropdown {
      border-radius: 50%;
      height: 50px;
      width: 50px;
      border: 1px solid black;
      object-fit: cover;
    }
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
    
      <a class="navbar-brand" href="#">Equilibrium</a>
    <!-- If the user is logged in, display a profile icon. -->
    
      <ul class="nav navbar-nav mr-auto">
    
     
          <li class="nav-item">
            <a>
              <img src="" class="profile-dropdown" alt="">
            </a>
          </li>
      
          <li class="nav-item" >
            <img src="/assets/glyphicons/user.png" class="profile-dropdown" alt="">
          </li>
   
    
      </ul>
    
    </nav>

我感谢任何帮助。感谢。

2 个答案:

答案 0 :(得分:0)

我在这里发布了Bootstrap 4工作导航栏的示例。这应该指向正确的方向。如果您还有任何疑问,请在评论中提问。

正如您所看到的,mr-auto类完美地运行在这里。它将右侧的内容推送到另一侧。 (mr-auto =&#34; margin-right:auto&#34;)

这是工作代码:

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">


<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Dropdown
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <a class="dropdown-item" href="#">Action</a>
                    <a class="dropdown-item" href="#">Another action</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#">Something else here</a>
                </div>
            </li>
            <li class="nav-item">
                <a class="nav-link disabled" href="#">Disabled</a>
            </li>
        </ul>
        <a class="navbar-brand" href="#">
            <p><i class="fa fa-user" aria-hidden="true"></i></p>
        </a>
    </div>
</nav>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您的问题是要将项目对齐。为此,您必须添加ml-auto而不是mr-auto。它会使所有项目保持正确对齐。