Home > Blockchain >  Align nav-bar to the right using bootstrap
Align nav-bar to the right using bootstrap

Time:11-30

I'm trying to align the navbar components to the right. The code is given below. I tried with ml-auto but it's not giving the desired result. The result that I'm getting is attached below.

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

<header class="bg-info">
  <div class="row text-white">
    <div class="col-md-6 col-9 p-3 pl-5">
      <h2>Header</h2>
    </div>
    <div class="col-md-6 col-3 my-auto ml-auto">
      <nav class="navbar navbar-expand-lg navbar-light">
        <button class="navbar-toggler ml-auto" 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">
          <!-- me-auto mb-2 mb-lg-0 -->
          <ul class="navbar-nav ml-auto">
            <li class="nav-item">
              <a class="nav-link active text-white" aria-current="page" href="#">Home</a
                  >
                </li>
                <li class="nav-item">
                  <a class="nav-link text-white" href="#">Know More</a>
            </li>
            <li class="nav-item">
              <a class="nav-link text-white" href="#">Actions</a>
            </li>
            <li class="nav-item">
              <a class="nav-link text-white" href="#">Gallery</a>
            </li>
            <li class="nav-item">
              <a class="nav-link text-white" href="#">Contact Us</a>
            </li>
          </ul>
        </div>
      </nav>
    </div>
  </div>
</header>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Result Current result I want the home, know more, etc.. content to be right-aligned. I have divided it initially into two columns. Then gave the second one the ml-auto class. What's the issue here?

CodePudding user response:

I checked safari, chrome, firefox and the snippet checker in StackOverflow.

All are showing the correct styling and not what you screenshot-ed. Maybe you have an extension that is injecting some sort of custom CSS? Or you don't have the bootstrap file loaded properly?

Your font also seems a bit off in the screenshot.

What my Chrome looks like

CodePudding user response:

Could be very easy. Remove all ml-auto's then use d-flex to justify-content-end (right). justify-content-start would be the left. But.... As somebody else pointed out. When I try your code - Your menu is on the right hand side and Header on the left as required.

<nav class="navbar navbar-expand-lg navbar-light d-flex justify-content-end">

  • Related