Home > Software engineering >  Why is my Bootstrap 5 NavBar brand aligned all the way left?
Why is my Bootstrap 5 NavBar brand aligned all the way left?

Time:10-01

I have the following HTML:

<!DOCTYPE html>
<html>

<head>
  <title>Bootstrap Demo</title>

  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6 fzT" crossorigin="anonymous">
</head>

<body>
  <div >
    <nav  style="background-color: green;">
      <a  href="#">My To Do's</a>
      <div >
        <div >
          <a  routerLink="">Checklist</a>
          <a  routerLink="all-tasks">All To Dos</a>
          <a  routerLink="about">About</a>
        </div>
      </div>
    </nav>
  </div>
</body>

</html>

And when I view it, the nav-brand is munched up against the left.

No padding!

Am I doing something wrong, or do I have to do the padding myself?

CodePudding user response:

I believe this is because the navbar class, which adds padding, defaults to 0 for "x padding":

/* bootstrap.css */
.navbar {
    --bs-navbar-padding-x: 0.5rem
}

To fix that, give the variable a value:

.navbar {
    /* What the docs use */
    --bs-navbar-padding-x: 0.5rem;
}
  • Related