skip to Main Content

I am using bootstrap, I’m still learing css and bootstrap. I would like to move links in ul to the far right of the screen. Please help

<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" routerLink="/home">

<img src="../assets/images/My project (1).png" width="40" height="20" class="d-inline-block align-top" alt="">
</a>
  
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-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">
        <div class="mr-auto"></div>
        <ul class="navbar-nav my-2 my-lg-0">
          <li class="nav-item active"><a class="nav-link" routerLink="/home">Home<span class="sr-only">(current)</span></a></li> 
          <li class="nav-item"><a class="nav-link" routerLink="/property">Property<span class="sr-only">(current)</span></a></li>                   
          <li class="nav-item"><a class="nav-link" routerLink="/about">About<span class="sr-only">(current)</span></a></li>
          
  
        </ul>
  
      </div>
</nav>

I tried justify content:right but it didnt work. I also tried text-end class but it doesn’t work. I also tried to use justify-content: space-between; and it didn’t work

2

Answers


  1. You may use the following code:

    .navbar ul {
      position: absolute;
      right: 0;
    }
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <a class="navbar-brand" routerLink="/home">
    
        <img src="../assets/images/My project (1).png" width="40" height="20" class="d-inline-block align-top" alt="">
      </a>
    
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-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">
        <div class="mr-auto"></div>
        <ul class="navbar-nav my-2 my-lg-0">
          <li class="nav-item active"><a class="nav-link" routerLink="/home">Home<span class="sr-only">(current)</span></a></li>
          <li class="nav-item"><a class="nav-link" routerLink="/property">Property<span class="sr-only">(current)</span></a></li>
          <li class="nav-item"><a class="nav-link" routerLink="/about">About<span class="sr-only">(current)</span></a></li>
        </ul>
      </div>
    </nav>

    Hope you find this useful! Anything else please let me know in comments.

    Login or Signup to reply.
  2. You can just apply margin-left: auto to your ul to move them to the right end.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search