Home  >  Q&A  >  body text

I can't align my logo with the navigation bar

I'm following a YouTube tutorial and I wrote the exact same code but I can't get my logo to align with the navigation like theirs

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.navbar {
  display: flex;
  align-items: center;
  padding: 20px;
}

nav {
  flex: 1;
  text-align: right;
}

nav ul {
  display: inline-block;
  list-style-type: none;
}

nav ul li {
  display: inline-block;
  margin-right: 20px;
}

a {
  text-decoration: none;
  color: #555;
}

p {
  color: #555;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title> STUDENT HUB </title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div class="navbar">
    <div class="logo">
      <img src="image/logo.png" width="125px" alt="this is an image">
    </div>
  </div>
  <nav>
    <ul>
      <li><a href="">Home</a></li>
      <li><a href="">Commu</a></li>
      <li><a href="">Report</a></li>
      <li><a href="">Help </a></li>
      <li><a href="">Account</a></li>
    </ul>
  </nav>
</body>

</html>

I tried using Vertical-align: center and Display: inline-block under the navigation bar selector but it didn't work either

P粉921130067P粉921130067158 days ago313

reply all(1)I'll reply

  • P粉378890106

    P粉3788901062024-04-03 10:39:48

    You must put the nav tag inside the navbar div.

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    .navbar {
      display: flex;
      align-items: center;
      padding: 20px;
    }
    
    nav {
      flex: 1;
      text-align: right;
    }
    
    nav ul {
      display: inline-block;
      list-style-type: none;
    }
    
    nav ul li {
      display: inline-block;
      margin-right: 20px;
    }
    
    a {
      text-decoration: none;
      color: #555;
    }
    
    p {
      color: #555;
    }
    
    
    
    
      
       STUDENT HUB 
      
    
    
    
      
      
    
    
    

    reply
    0
  • Cancelreply