skip to Main Content

here i am again, i recently solved a problem where I could not get the navbar brand to go into the middle of my nav bar, however, that was fixed, but now I want to add a button right before the right navigation toggle. I have tried multiple ways, like text-align, and a few other methods that bootstrap has like d-flex. however I cannot seem to override the justify-content-between so i can get my sign up button to appear right before the right navigation toggle. I have left a photo below for better reference. I have also included the code for my navigation bar below the photo link. thanks in advance!
picture of what I am trying to accomplish

<header>
    <nav class="navbar navbar-dark bg-dark" aria-label="Dark offcanvas navbar">
    <div class="container-fluid d-flex justify-content-between">
      <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#leftMainNav" aria-controls="leftMainNav" aria-label="Toggle left navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <a class="navbar-brand" href="index.php">
                <img src="assets/images/logo-l.png" class="img-fluid" alt="CBS Logo">
                CherryBerry <span class="text-red"> Studios </span>
              </a>
      <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#rightMainNav" aria-controls="rightMainNav" aria-label="Toggle right navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="offcanvas offcanvas-end text-bg-dark" data-bs-scroll="true" tabindex="-1" id="rightMainNav" aria-labelledby="rightMainNav">
        <div class="offcanvas-header">
          <h5 class="offcanvas-title" id="offcanvasNavbarDarkLabel">Offcanvas</h5>
          <button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
        </div>
        <div class="offcanvas-body">
          <ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
            <li class="nav-item">
              <a class="nav-link active" aria-current="page" href="#">Home</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Link</a>
            </li>
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                Dropdown
              </a>
              <ul class="dropdown-menu">
                <li><a class="dropdown-item" href="#">Action</a></li>
                <li><a class="dropdown-item" href="#">Another action</a></li>
                <li>
                  <hr class="dropdown-divider">
                </li>
                <li><a class="dropdown-item" href="#">Something else here</a></li>
              </ul>
            </li>
          </ul>
        </div>
      </div>
      <div class="offcanvas offcanvas-start text-bg-dark" data-bs-scroll="true" tabindex="-1" id="leftMainNav" aria-labelledby="leftMainNav">
        <div class="offcanvas-header">
          <h5 class="offcanvas-title" id="offcanvasNavbarDarkLabel">Offcanvas</h5>
          <button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
        </div>
        <div class="offcanvas-body">
          <ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
            <li class="nav-item">
              <a class="nav-link active" aria-current="page" href="#">Home</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Link</a>
            </li>
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                Dropdown
              </a>
              <ul class="dropdown-menu">
                <li><a class="dropdown-item" href="#">Action</a></li>
                <li><a class="dropdown-item" href="#">Another action</a></li>
                <li>
                  <hr class="dropdown-divider">
                </li>
                <li><a class="dropdown-item" href="#">Something else here</a></li>
              </ul>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </nav>
  </header>

2

Answers


  1. you need to replace some code…

    <!-- replace this lines (right toggler) -->
    <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#rightMainNav" aria-controls="rightMainNav" aria-label="Toggle right navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    
    <!-- with the below code -->
    <div>
      <button class="btn btn-outline-danger" type="button" aria-label="sign up">
        <span>Sign up</span>
      </button>
      <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#rightMainNav" aria-controls="rightMainNav" aria-label="Toggle right navigation">
        <span class="navbar-toggler-icon"></span>
      </button>
    </div>
    
    Login or Signup to reply.
  2. What I was trying to say in comments, was that since you already have a flex container and your toggler button as a flex item, instead of messing up the justify-content, you may just wrap that element inside a new div container and include inside it the element that should be next to the already existing one.

    This is in detail the modification:

      <div class="toggler-container">
        <div class="signup">sign up</div>
        <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#rightMainNav" aria-controls="rightMainNav" aria-label="Toggle right navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
      </div>
    

    And this is the whole demo:

    .signup{
      display: inline-block;
      border: solid 1px red;
      padding: .2em;
      color: red;
      
      /* same sizing as the sibling */
      box-sizing: border-box;
      padding: 0.25rem 0.75rem;  
      border-radius: 0.25rem;  
      
      /* will stretch the height of signup to be as much as the container */  
      align-self: stretch;  
    }
    
    /*this is just to style the container of signup and hamburger toggler*/
    .toggler-container{
      display: flex;
      align-items: center;
      gap: 0.5em;
    }
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    
    <header>
      <nav class="navbar navbar-dark bg-dark" aria-label="Dark offcanvas navbar">
        <div class="container-fluid d-flex justify-content-between">
          <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#leftMainNav" aria-controls="leftMainNav" aria-label="Toggle left navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <a class="navbar-brand" href="index.php">
            <img src="assets/images/logo-l.png" class="img-fluid" alt="CBS Logo"> CherryBerry <span class="text-red"> Studios </span>
          </a>
          <div class="toggler-container">
            <div class="signup">sign up</div>
            <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#rightMainNav" aria-controls="rightMainNav" aria-label="Toggle right navigation">
              <span class="navbar-toggler-icon"></span>
            </button>
          </div>
          <div class="offcanvas offcanvas-end text-bg-dark" data-bs-scroll="true" tabindex="-1" id="rightMainNav" aria-labelledby="rightMainNav">
            <div class="offcanvas-header">
              <h5 class="offcanvas-title" id="offcanvasNavbarDarkLabel">Offcanvas</h5>
              <button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
            </div>
            <div class="offcanvas-body">
              <ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
                <li class="nav-item">
                  <a class="nav-link active" aria-current="page" href="#">Home</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Link</a>
                </li>
                <li class="nav-item dropdown">
                  <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                    Dropdown
                  </a>
                  <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="#">Action</a></li>
                    <li><a class="dropdown-item" href="#">Another action</a></li>
                    <li>
                      <hr class="dropdown-divider">
                    </li>
                    <li><a class="dropdown-item" href="#">Something else here</a></li>
                  </ul>
                </li>
              </ul>
            </div>
          </div>
          <div class="offcanvas offcanvas-start text-bg-dark" data-bs-scroll="true" tabindex="-1" id="leftMainNav" aria-labelledby="leftMainNav">
            <div class="offcanvas-header">
              <h5 class="offcanvas-title" id="offcanvasNavbarDarkLabel">Offcanvas</h5>
              <button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
            </div>
            <div class="offcanvas-body">
              <ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
                <li class="nav-item">
                  <a class="nav-link active" aria-current="page" href="#">Home</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Link</a>
                </li>
                <li class="nav-item dropdown">
                  <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                    Dropdown
                  </a>
                  <ul class="dropdown-menu">
                    <li><a class="dropdown-item" href="#">Action</a></li>
                    <li><a class="dropdown-item" href="#">Another action</a></li>
                    <li>
                      <hr class="dropdown-divider">
                    </li>
                    <li><a class="dropdown-item" href="#">Something else here</a></li>
                  </ul>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </nav>
    </header>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search