Home > Enterprise >  How do I inline a div in navbar element
How do I inline a div in navbar element

Time:07-25

I am having some problems with my html. I am making a navbar offcanvas. Here is my code:

    <nav >
        <div >
          <a  href="#">Olau Pla Richart</a>
          <button  type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
            <span ></span>
          </button>
          <div  tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
            <div >
              <h4  id="offcanvasDarkNavbarLabel">Menu</h4>
              <button type="button"  data-bs-dismiss="offcanvas" aria-label="Close"></button>
            </div>
            <div >
              <ul >
                <li >
                    <h5><a  href="#home"> Home</a></h5>
                </li>
                <li >
                    <h5><a  href="#about"> About</a></h5>
                </li>
                <li >
                    <h5><a  href="#contact"> Contact</a></h5>
                  </li>
                <li >
                    <h5><a  href="#"> Blog</a></h5>
                </li>
              </ul>
            </div>
          </div>
        </div>
        <div>
            <a>Test</a>
        </div>
    </nav>

What I am trying to do is get the Test in the same line as Olau Pla Richart. Here is what my code does at the moment:

I tried adding display: inline; and display: inline-block; but I got no change.

CodePudding user response:

You need to move your div, also wrap a and that same div (now span) in a div to not get spaced because bootstrap 5 has this rule .navbar > .container-fluid { ... , justify-content: space-between}

.test {
  color: white
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">

<nav >
  <div >
    <div>
      <a  href="#">Olau Pla Richart</a>
      <span>
       <a  href="#">Test</a>
      </span>
    </div>
    <button  type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
      <span ></span>
    </button>
    <div  tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
      <div >
        <h4  id="offcanvasDarkNavbarLabel">Menu</h4>
        <button type="button"  data-bs-dismiss="offcanvas" aria-label="Close"></button>
      </div>
      <div >
        <ul >
          <li >
            <h5><a  href="#home"> Home</a></h5>
          </li>
          <li >
            <h5><a  href="#about"> About</a></h5>
          </li>
          <li >
            <h5><a  href="#contact"> Contact</a></h5>
          </li>
          <li >
            <h5><a  href="#"> Blog</a></h5>
          </li>
        </ul>
      </div>
    </div>
  </div>
</nav>

CodePudding user response:

Try border-bottom (border-bottom: 1px solid #ccc) details

CodePudding user response:

Try adding display: flex; to your navbar class.

CodePudding user response:

You do not need any additional CSS, You just need to place the a in the the proper place (after .navbar-brand), and add .navbar-text to get the correct color for .navbar-dark/.navbar-light. It will be centered between .navbar-brand and .navbar-toggler by default. You can use .me-auto to left-align it, or .ms-auto to right-align.

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

<nav >
  <div >
    <a  href="#">Olau Pla Richart</a>
    <a >Test</a>
    <button  type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
          <span ></span>
        </button>
    <div  tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
      <div >
        <h4  id="offcanvasDarkNavbarLabel">Menu</h4>
        <button type="button"  data-bs-dismiss="offcanvas" aria-label="Close"></button>
      </div>
      <div >
        <ul >
          <li >
            <h5><a  href="#home"> Home</a></h5>
          </li>
          <li >
            <h5><a  href="#about"> About</a></h5>
          </li>
          <li >
            <h5><a  href="#contact"> Contact</a></h5>
          </li>
          <li >
            <h5><a  href="#"> Blog</a></h5>
          </li>
        </ul>
      </div>
    </div>

  </div>

</nav>

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

  • Related