skip to Main Content

I am 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 navbar selector but it didn’t work either

5

Answers


  1. You have to put your 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;
    }
    <!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>
        <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>
      </div>
      
    </body>
    
    </html>
    Login or Signup to reply.
  2. Try this instead

    <nav>
            <ul>
              <li><img src="image/logo.png" width="125px" alt="this is an image"></li>
                <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>
    
    Login or Signup to reply.
  3. * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }
      
    
      .navbar_container{
        display: flex;
        flex-direction: row;
        align-items: center;
      }
      
      .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;
      }
    <div class="navbar_container">
            <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>
    </div>
    Login or Signup to reply.
  4. Just move your closing tag of the navBar under the nav closing tag

    Login or Signup to reply.
  5. you have done it almost correctly. Just move the nav tag into div

    <!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>
        <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>
      </div>
      
    </body>
    
    </html>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search