Home > Net >  Bootstrap-5 navbar button from left to right
Bootstrap-5 navbar button from left to right

Time:01-24

I want to change this bootstrap5 navbar buttons from left side to a right side, but I don't know how to do that using css or bootstrap5, guys how can I do this?

My Code:

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

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

<nav >
        <div >
          <a  href="#">
            <h1>Pondadb</h1>
          </a>
          <button  type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span ></span>
          </button>
        
          <div  id="navbarSupportedContent">
            <ul >
              <li >
                <a  href="#">About</a>
              </li>
              <li >
                <a  href="#">Contact</a>
              </li>
              <li >
                <a  href="#">Login</a>
              </li>
              <li >
                <a  href="#">Singn-Up</a>
              </li>
            </ul>
          </div>
        </div>
      </nav>

CodePudding user response:

You have .mr-auto which is Bootstrap 4's version of margin-right: auto;. This does not work in B5 and the correct class would be .me-auto.

However, you don't want margin-right: auto;, you want margin-left: auto; to push the elements to the right. In B5, you should use ms-auto.

Spacing · Bootstrap v5.3

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

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

<nav >
  <div >
    <a  href="#">
      <h1>Pondadb</h1>
    </a>
    <button  type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span ></span>
          </button>

    <div  id="navbarSupportedContent">
      <ul >
        <li >
          <a  href="#">About</a>
        </li>
        <li >
          <a  href="#">Contact</a>
        </li>
        <li >
          <a  href="#">Login</a>
        </li>
        <li >
          <a  href="#">Singn-Up</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

CodePudding user response:

I think changing of "mr-auto" in into "ml-auto" should help. It is bootstrap form of margin-right: auto, so it means that it is positioned at right. If I undertand you right, you want it to be on right side, so change it to margin-left: auto = ml-auto.

  • Related