Home > Enterprise >  How can i move this navbar menu to the right side?
How can i move this navbar menu to the right side?

Time:09-21

How can i move this navbar menu to the right side ?

I am not able to move this navbar menu on the right side. I have tried float right method. what will be the best solution ?

I tried many ways and no result yet, could you help thankfully to solve my problem!

Here is my code

    <html>

    <head>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
            integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">

        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">

        <title>TechSite</title>

        <style>
            .navbar-brand{
                font-size: 2rem;
            }
            ul.navbar-nav {
               font-size: 1.15rem;
            }
            .nav-link {
                padding: .3rem 1rem;
                color: white;
            }

            .nav-link:hover {
                color: white;
            }

            button.navbar-toggler {
                color: white;
            }

            p {
                color: gray;
            }
        </style>

    </head>

    <body>

        <!-- navbar -->

        <nav class="navbar navbar-expand-lg  bg-dark fixed-top">

            <div class="container-fluid">

                <a class="navbar-brand" href="#" style="color: red;">
                    TechSite
                </a>

                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                    aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon" style="color: white;"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav float-end">
                        <li class="nav-item">
                            <a class="nav-link active rounded" aria-current="page" href="#"
                                style="color: rgb(173, 173, 173);border: 1px solid wheat;">
                                Home
                            </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">
                                Services
                            </a>
                            <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                                <li><a class="dropdown-item" href="#">App Development</a></li>
                                <li><a class="dropdown-item" href="#">Game Development</a></li>
                                <li><a class="dropdown-item" href="#">Web Development</a></li>
                            </ul>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" style="color: white;">About</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="#" style="color: white;">Contact</a>
                        </li>
                    </ul>
                </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>

Is it better idea to use Bootstrap 5 to solve the problem?

CodePudding user response:

In flex system you give the container navbar-collapse the class justify-content-center and your option menu will be aligned to the right side.

Update your HTML code with the following

<nav class="navbar navbar-expand-lg  bg-dark fixed-top">

  <div class="container-fluid">

      <a class="navbar-brand" href="#" style="color: red;">
          TechSite
      </a>

      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
          aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon" style="color: white;"></span>
      </button>

      <div class="collapse navbar-collapse justify-content-center" id="navbarNav">
          <ul class="navbar-nav float-end">
            <li class="nav-item">
              <a class="nav-link active rounded" aria-current="page" href="#"
                  style="color: rgb(173, 173, 173);border: 1px solid wheat;">
                  Home
              </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">
                      Services
                  </a>
                  <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                      <li><a class="dropdown-item" href="#">App Development</a></li>
                      <li><a class="dropdown-item" href="#">Game Development</a></li>
                      <li><a class="dropdown-item" href="#">Web Development</a></li>
                  </ul>
              </li>
              <li class="nav-item">
                  <a class="nav-link" href="#" style="color: white;">About</a>
              </li>
              <li class="nav-item">
                  <a class="nav-link" href="#" style="color: white;">Contact</a>
              </li>
              
          </ul>
      </div>

  </div>

</nav>
  • Related