Home > Enterprise >  Move Items in Bootstrap 5 Navigation Bar
Move Items in Bootstrap 5 Navigation Bar

Time:10-04

So, I'm trying to align the items of a Bootstrap 5 navigation bar to the side as shown in this screenshot

Example

I expected it to move to the side but it didn't work. I didn't see any change in the site. (I was using Live Server extension) Probably just changed something but Bootstrap overrides it.

While I was making this question, in the similar questions, none of them was related or it wasn't in Bootstrap 5.

I attempted using margin, padding, text-align: right / text-align:flex-end;, and align-items:right / align-items:flex-right on navbar-nav but to no avail.

Here is some code:

navbar-nav {
  padding: 20px;
  margin: 20px;
}

navbar-nav {
  text-align: right;
  align-items: right;
}

navbar-nav {
  text-align: flex-end;
  align-items: flex-end;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="stylesheet" href="styles.css">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Scratch Bookmarklets</title>
</head>

<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container-fluid">
      <a class="navbar-brand" href="#">Scratch Bookmarklets</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="#">Home</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-bs-toggle="dropdown" aria-expanded="false">
            Dropdown
          </a>
            <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
              <li><a class="dropdown-item" href="#">Action</a></li>
              <li><a class="dropdown-item" href="#">Another action</a></li>
              <li>
                <hr class="dropdown-divider">
              </li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
            </ul>
          </li>
          <li class="nav-item">
            <a class="nav-link disabled">Disabled</a>
          </li>
        </ul>
        <form class="d-flex">
          <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
          <button class="btn btn-outline-success" type="submit">Search</button>
        </form>
      </div>
    </div>
  </nav>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
</body>

</html>

Thank you in advance.

CodePudding user response:

enter image description here

Just change me-auto with ms-auto on navbar-nav.

<ul class="navbar-nav me-auto mb-2 mb-lg-0">

TO

<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
  • Related