Home > Blockchain >  Why Justify-content not working in nav-bar in html css
Why Justify-content not working in nav-bar in html css

Time:05-24

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>
</head>

<body>
    <nav >
        <div >
            xMu5<span >ic</span>
        </div>
        <div >
            <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>
    <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>
   <br>  
 <h1>   
 hi 
</h1>
</body>
</html>

CodePudding user response:

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

CodePudding user response:

Use the text-align:

text-align: center;

CodePudding user response:

You placed a extra hr inside .navbar. I removed it. You have a border-bottom for .navbar so you don't need to hr. Also, justify-items isn't a correct style.

<!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; (removed) */ 
    }
    
    .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 >
    <div >
      xMu5<span >ic</span>
    </div>
    <div >
      <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>
  </nav>

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

</html>

CodePudding user response:

text-align: center;

Please use the text-align property to align the content to center

  • Related