Bootstrap 弯曲中间和末端

Bootstrap Flex middle and end

我正在竭尽全力尝试将导航项目居中并将按钮放在最后。我设法将按钮放到最后但无法弄清楚如何将项目+品牌居中。如有任何帮助,我们将不胜感激!

<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
  <title>DOC</title>
</head>

<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container-fluid">
      <a class="navbar-brand" href="#">Navbar</a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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 me-auto mb-2 mb-lg-0">
          <li class="nav-item">
            <a class="nav-link active" aria-current="page" href="#">Services</a>
          </li>

          <li class="nav-item">
            <a class="nav-link active" aria-current="page" href="#">The team</a>
          </li>

          <li class="nav-item">
            <a class="nav-link active" aria-current="page" href="#">Contact Us</a>
          </li>
        </ul>
        <div class="d-flex">
          <button class="btn btn-outline-success" type="submit">Login</button>
        </div>
      </div>
    </div>
  </nav>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>

</html>

你不能在单个 flex 中做这样的事情(使用 margin auto 可能是可能的,但我不确定)但是使用两个嵌套的 flex 框可以帮助你

在此代码中,我使用 div.collapse 作为第一个 flexbox,ul.navbar-nav 作为第二个

<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse justify-content-between navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav w-100 justify-content-center mb-2 mb-lg-0">
            <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#">Services</a>
            </li>

            <li class="nav-item">
                <a class="nav-link" aria-current="page" href="#">The team</a>
            </li>

            <li class="nav-item">
                <a class="nav-link" aria-current="page" href="#">Contact Us</a>
            </li>
        </ul>
        <div class="d-flex">
            <button class="btn btn-outline-success" type="submit">Login</button>
        </div>
    </div>
</div>

这是它如何工作的现场演示,如果您还有其他意思,请告诉我

https://jsfiddle.net/mahdiar_mansouri/fohgr7ew/7/