Why Justify-content not working in nav-bar in html css

Issue

I am creating a project in HTML,CSS & Flask. Whenever I check my nav bar in the live server ‘justify content’ is not working, I try to figure out via fixing the sizing of ul & li elements and I give main container 100% width but this way is also not working!
How can I solve and avoid these mistakes when we are using justify-content and also give some tips for using justify-content?

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>
    Document
  </title>
  <style>
    .navbar {
      display: flex;
      align-items: center;
      border-bottom: 2px solid lightgray;
      width: 100%;
      justify-content: space-between;
      justify-items: flex-start;
    }
    
    .logo {
      color: blueviolet;
      font-size: 35px;
      width: 110px;
    }
    
    .navitems ul {
      display: flex;
      align-items: center;
      width: 350px;
    }
    
    li {
      color: tomato;
      font-weight: 500;
      list-style: none;
      text-decoration: none;
    }
    
    li a {
      text-decoration: none;
      color: tomato;
      padding: 3px;
      font-size: 19px;
    }
  </style>
</head>

<body>
  <nav class="navbar">
    <div class="logo">
      xMu5<span class="titel">ic</span>
    </div>
    <div class="navitems">
      <ul>
        <li>
          <a href="">
Home
</a>
        </li>
        <li>
          <a href="">
Blog
</a>
        </li>
        <li>
          <a href="">
Services
</a>
        </li>
        <li>
          <a href="">
Contact Us
</a>
        </li>
        <li>
          <a href="">
About Us
</a>
        </li>
      </ul>
    </div>
    <hr>
  </nav>

  <br>
  <h1>
    hi
  </h1>
</body>

</html>

Solution

Because you add <hr> tag inside <nav class="navbar">. so move it outside <nav class="navbar"> then it works.

Answered By – Amandeep Singh

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.