css Bootstrap-从左到右5个导航栏按钮

vbkedwbf  于 2023-01-27  发布在  Bootstrap
关注(0)|答案(2)|浏览(200)

我想把这个bootstrap5导航栏按钮从左边改为右边,但是我不知道如何使用cssbootstrap5,伙计们,我怎么能做到呢?
我的代码:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" 
    rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" 
    crossorigin="anonymous">

 <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container">
          <a class="navbar-brand" href="#">
            <h1>Pondadb</h1>
          </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="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">About</a>
              </li>
              <li class="nav-item">
                <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Contact</a>
              </li>
              <li class="nav-item">
                <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Login</a>
              </li>
              <li class="nav-item">
                <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Singn-Up</a>
              </li>
            </ul>
          </div>
        </div>
      </nav>
iovurdzv

iovurdzv1#

你有.mr-auto,它是Bootstrap 4的margin-right: auto;版本,在B5中不起作用,正确的类应该是.me-auto
然而,你不需要margin-right: auto;,你需要margin-left: auto;把元素推到右边,在B5中,你应该使用ms-auto
Spacing · Bootstrap v5.3

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container">
    <a class="navbar-brand" href="#">
      <h1>Pondadb</h1>
    </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 ms-auto">
        <li class="nav-item active">
          <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">About</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Contact</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Login</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-primary mx-lg-2 mx-0 my-lg-0 my-2" href="#">Singn-Up</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
i1icjdpr

i1icjdpr2#

我认为将中的“mr-auto”更改为“ml-auto”会有所帮助。它是margin-right的引导形式:auto,所以它意味着它被放置在右边。如果我理解你的意思是右边,你希望它在右边,所以把它改为margin-left:自动= ml-自动。

相关问题