Home > OS >  bootstrap 5 navbar element
bootstrap 5 navbar element

Time:10-11

I used bootstrap to form my of canvas navbar that expands when large size is reached, however, I need my navbar elements to be centered when the elements are expanded. How should I do that?. here is my code so far. I tried to use justify-content-center and using grid system but nothing of these worked with me

body {
  font-family: 'Lexend Deca', sans-serif;
  background-color: white;
}

input:hover,
input:focus {
  outline: 0px !important;
  -webkit-appearance: none;
  box-shadow: none !important;
  border-color: rgb(206, 212, 218) !important;
}

#first_btn {
  border-color: rgb(206, 212, 218);
  color: #000000;
}

#first_btn:hover {
  background-color: #000000;
  color: rgb(206, 212, 218);
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Gym</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6 fzT" crossorigin="anonymous">
  <link rel="stylesheet" href="app.css">
  <!-- fonts -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Lexend Deca:wght@400;500;600&display=swap" rel="stylesheet">
</head>

<body>
  <nav >
    <div >
      <a  href="#">FitFat Studio</a>
      <button  type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar">
                <span ></span>
            </button>
      <div  tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
        <div >
          <h5  id="offcanvasNavbarLabel">FitFat Studio</h5>
          <button type="button"  data-bs-dismiss="offcanvas" aria-label="Close"></button>
        </div>
        <div >
          <ul >
            <li >
              <a  aria-current="page" href="#">Home</a>
            </li>
            <li >
              <a  aria-current="page" href="#">Notifications <span
                                    >5</span>
                            </a>

            </li>
            <li >
              <a  href="#">work with us</a>
            </li>
            <li >
              <a  href="#">contact us</a>
            </li>
          </ul>
          <form id="first-form"  role="search">
            <input  type="search" placeholder="Search" aria-label="Search">
            <button id="first_btn"  type="submit">Search</button>
          </form>
        </div>
      </div>
    </div>
  </nav>



  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a RTT6rIHI7NnikvbZlHgTPOOmMi466C8" crossorigin="anonymous"></script>
</body>

</html>

CodePudding user response:

A quick solution could be adding justify-content-center class to the offcanvas-body element and also you should remove flex-grow-1 from ul.navbar-nav for the justify-content-center class to take effect.

Here's a demo with the changes in place (use Full Page option on top right of the snippet to actually see the changes):

body {
  font-family: 'Lexend Deca', sans-serif;
  background-color: white;
}

input:hover,
input:focus {
  outline: 0px !important;
  -webkit-appearance: none;
  box-shadow: none !important;
  border-color: rgb(206, 212, 218) !important;
}

#first_btn {
  border-color: rgb(206, 212, 218);
  color: #000000;
}

#first_btn:hover {
  background-color: #000000;
  color: rgb(206, 212, 218);
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Gym</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6 fzT" crossorigin="anonymous">
  <link rel="stylesheet" href="app.css">
  <!-- fonts -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Lexend Deca:wght@400;500;600&display=swap" rel="stylesheet">
</head>

<body>
  <nav >
    <div >
      <a  href="#">FitFat Studio</a>
      <button  type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar">
                <span ></span>
            </button>
      <div  tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
        <div >
          <h5  id="offcanvasNavbarLabel">FitFat Studio</h5>
          <button type="button"  data-bs-dismiss="offcanvas" aria-label="Close"></button>
        </div>
        <!-- add "justify-content-center" here -->
        <div >
          <!-- remove flex-grow-1 for the above class to take effect -->
          <ul >
            <li >
              <a  aria-current="page" href="#">Home</a>
            </li>
            <li >
              <a  aria-current="page" href="#">Notifications <span
                                    >5</span>
                            </a>

            </li>
            <li >
              <a  href="#">work with us</a>
            </li>
            <li >
              <a  href="#">contact us</a>
            </li>
          </ul>
          <form id="first-form"  role="search">
            <input  type="search" placeholder="Search" aria-label="Search">
            <button id="first_btn"  type="submit">Search</button>
          </form>
        </div>
      </div>
    </div>
  </nav>



  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a RTT6rIHI7NnikvbZlHgTPOOmMi466C8" crossorigin="anonymous"></script>
</body>

</html>

CodePudding user response:

According to your code just replace "justify-content-end" with "justify-content-center"

   <ul >
  • Related